[perl-Gtk3] When marshalling key-value pairs, preserve their order



commit bd39c3c6f329c50497b8f4a7aabf051d7dd17734
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date:   Tue Oct 25 16:56:15 2016 +0200

    When marshalling key-value pairs, preserve their order
    
    Currently, this applies to Gtk3::ListStore::insert_with_values,
    Gtk3::ListStore::set, Gtk3::TreeStore::insert_with_values,
    Gtk3::TreeStore::set and Gtk3::Gdk::Pixbuf::save*.

 lib/Gtk3.pm |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index bd3eeec..afeaf8f 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -2178,9 +2178,11 @@ sub _unpack_keys_and_values {
     @keys = @{$keys_and_values->[0]};
     @values = @{$keys_and_values->[1]};
   } elsif (@$keys_and_values % 2 == 0) {
-    my %keys_to_vals = @$keys_and_values;
-    @keys = keys %keys_to_vals;
-    @values = values %keys_to_vals;
+    # To preserve the order of the key-value pairs, avoid creating an
+    # intermediate hash.
+    my @range = 0 .. (@$keys_and_values/2-1);
+    @keys = @$keys_and_values[map { 2*$_ } @range];
+    @values = @$keys_and_values[map { 2*$_+1 } @range];
   } else {
     return ();
   }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]