[shotwell] Use newer comparators in sidebar code: Bug #719284



commit 23f79a90cf69e0fce4bdfbdd20eaae189f637b13
Author: Wolfgang Steitz <wolfer7 web de>
Date:   Tue Feb 17 12:35:02 2015 -0800

    Use newer comparators in sidebar code: Bug #719284

 src/events/Branch.vala  |    4 +-
 src/sidebar/Branch.vala |   62 +++++++++++++++++-----------------------------
 2 files changed, 25 insertions(+), 41 deletions(-)
---
diff --git a/src/events/Branch.vala b/src/events/Branch.vala
index 878f309..114f85b 100644
--- a/src/events/Branch.vala
+++ b/src/events/Branch.vala
@@ -322,11 +322,11 @@ public class Events.Branch : Sidebar.Branch {
     }
     
     private void graft_event(Sidebar.Entry parent, Event event,
-        owned CompareDataFunc<Sidebar.Entry>? comparator = null) {
+        owned CompareFunc<Sidebar.Entry>? comparator = null) {
         Events.EventEntry entry = new Events.EventEntry(event);
         entry_map.set(event, entry);
         
-        graft(parent, entry, (owned) comparator);
+        graft(parent, entry, comparator);
     }
     
     private void reparent_event(Event event, Sidebar.Entry new_parent) {
diff --git a/src/sidebar/Branch.vala b/src/sidebar/Branch.vala
index 91916f0..a6c3ee8 100644
--- a/src/sidebar/Branch.vala
+++ b/src/sidebar/Branch.vala
@@ -39,23 +39,22 @@ public class Sidebar.Branch : Object {
         
         public Sidebar.Entry entry;
         public weak Node? parent;
-        public CompareDataFunc<Sidebar.Entry> comparator;
+        public CompareFunc<Sidebar.Entry> comparator;
         public Gee.SortedSet<Node>? children = null;
         
-        public Node(Sidebar.Entry entry, Node? parent,
-            owned CompareDataFunc<Sidebar.Entry> comparator) {
+        public Node(Sidebar.Entry entry, Node? parent, CompareFunc<Sidebar.Entry> comparator) {
             this.entry = entry;
             this.parent = parent;
-            this.comparator = (owned) comparator;
+            this.comparator = comparator;
         }
         
-        private static int comparator_wrapper(Node? a, Node? b) {
-            if (a == b)
+        private static int comparator_wrapper(Node anode, Node bnode) {
+            if (anode == bnode)
                 return 0;
             
-            assert(a.parent == b.parent);
+            assert(anode.parent == bnode.parent);
             
-            return a.parent.comparator(a.entry, b.entry);
+            return anode.parent.comparator(anode.entry, bnode.entry);
         }
         
         public bool has_children() {
@@ -172,16 +171,16 @@ public class Sidebar.Branch : Object {
             cb(this);
         }
         
-        public void change_comparator(owned CompareDataFunc<Sidebar.Entry> comparator, bool recursive,
+        public void change_comparator(CompareFunc<Sidebar.Entry> comparator, bool recursive,
             ChildrenReorderedCallback cb) {
-            this.comparator = (owned) comparator;
+            this.comparator = comparator;
             
             // reorder children, but need to do manual recursion to set comparator
             reorder_children(false, cb);
             
             if (recursive) {
                 foreach (Node child in children)
-                    child.change_comparator((owned) comparator, true, cb);
+                    child.change_comparator(comparator, true, cb);
             }
         }
     }
@@ -189,7 +188,7 @@ public class Sidebar.Branch : Object {
     private Node root;
     private Options options;
     private bool shown = true;
-    private CompareDataFunc<Sidebar.Entry> default_comparator;
+    private CompareFunc<Sidebar.Entry> default_comparator;
     private Gee.HashMap<Sidebar.Entry, Node> map = new Gee.HashMap<Sidebar.Entry, Node>();
     
     public signal void entry_added(Sidebar.Entry entry);
@@ -204,19 +203,11 @@ public class Sidebar.Branch : Object {
     
     public signal void show_branch(bool show);
     
-    public Branch(Sidebar.Entry root, Options options, 
-        owned CompareDataFunc<Sidebar.Entry> default_comparator,
-        owned CompareDataFunc<Sidebar.Entry>? root_comparator = null) {
-        this.default_comparator = (owned) default_comparator;
-        
-        CompareDataFunc<Sidebar.Entry>? broken_ternary_workaround;
-        
-        if (root_comparator != null)
-            broken_ternary_workaround = (owned) root_comparator;
-        else
-            broken_ternary_workaround = (owned) default_comparator;
-
-        this.root = new Node(root, null, (owned) broken_ternary_workaround);
+    public Branch(Sidebar.Entry root, Options options, CompareFunc<Sidebar.Entry> default_comparator,
+        CompareFunc<Sidebar.Entry>? root_comparator = null) {
+        this.default_comparator = default_comparator;
+        this.root = new Node(root, null,
+            (root_comparator != null) ? root_comparator : default_comparator);
         this.options = options;
         
         map.set(root, this.root);
@@ -254,7 +245,7 @@ public class Sidebar.Branch : Object {
     }
     
     public void graft(Sidebar.Entry parent, Sidebar.Entry entry,
-        owned CompareDataFunc<Sidebar.Entry>? comparator = null) {
+        CompareFunc<Sidebar.Entry>? comparator = null) {
         assert(map.has_key(parent));
         assert(!map.has_key(entry));
         
@@ -262,15 +253,8 @@ public class Sidebar.Branch : Object {
             set_show_branch(true);
         
         Node parent_node = map.get(parent);
-        
-        CompareDataFunc<Sidebar.Entry>? broken_ternary_workaround;
-        
-        if (comparator != null)
-            broken_ternary_workaround = (owned) comparator;
-        else
-            broken_ternary_workaround = (owned) default_comparator;
-        
-        Node entry_node = new Node(entry, parent_node, (owned) broken_ternary_workaround);
+        Node entry_node = new Node(entry, parent_node,
+            (comparator != null) ? comparator : default_comparator);
         
         parent_node.add_child(entry_node);
         map.set(entry, entry_node);
@@ -347,16 +331,16 @@ public class Sidebar.Branch : Object {
         entry_node.reorder_children(recursive, children_reordered_callback);
     }
     
-    public void change_all_comparators(owned CompareDataFunc<Sidebar.Entry>? comparator) {
-        root.change_comparator((owned) comparator, true, children_reordered_callback);
+    public void change_all_comparators(CompareFunc<Sidebar.Entry>? comparator) {
+        root.change_comparator(comparator, true, children_reordered_callback);
     }
     
     public void change_comparator(Sidebar.Entry entry, bool recursive,
-        owned CompareDataFunc<Sidebar.Entry>? comparator) {
+        CompareFunc<Sidebar.Entry>? comparator) {
         Node? entry_node = map.get(entry);
         assert(entry_node != null);
         
-        entry_node.change_comparator((owned) comparator, recursive, children_reordered_callback);
+        entry_node.change_comparator(comparator, recursive, children_reordered_callback);
     }
     
     public int get_child_count(Sidebar.Entry parent) {


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