[geary/cherry-pick-ac8c176e] Merge branch 'mjog/lru-cache-intermittent-test-failure' into 'mainline'



commit a4fb22782cf74823c36f3d9c177dae3925b39d3e
Author: Michael Gratton <mike vee net>
Date:   Tue Mar 17 04:04:29 2020 +0000

    Merge branch 'mjog/lru-cache-intermittent-test-failure' into 'mainline'
    
    Util.Cache.Lru: Fix intermittent unit test failure
    
    Closes #739
    
    See merge request GNOME/geary!435
    
    (cherry picked from commit ac8c176e781a9495cb953a047f44c3b4e98c8cdc)
    
    6da19c5b Util.Cache.Lru: Fix intermitted unit test failure

 src/client/util/util-cache.vala | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/src/client/util/util-cache.vala b/src/client/util/util-cache.vala
index 44097d89..f054e32e 100644
--- a/src/client/util/util-cache.vala
+++ b/src/client/util/util-cache.vala
@@ -13,8 +13,15 @@ public class Util.Cache.Lru<T> : Geary.BaseObject {
 
 
         public static int lru_compare(CacheEntry<T> a, CacheEntry<T> b) {
-            return (a.key == b.key)
-                ? 0 : (int) (a.last_used - b.last_used);
+            if (a.key == b.key) {
+                return 0;
+            }
+            if (a.last_used != b.last_used) {
+                return (int) (a.last_used - b.last_used);
+            }
+            // If all else is equal, use the keys themselves to
+            // stabilise the sorting order
+            return GLib.strcmp(a.key, b.key);
         }
 
 


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