[gnome-calculator] search-provider: cache only a limited number of equations



commit 15d071611531075d1b35c5025399ca22997d89d8
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Aug 27 18:56:09 2018 +0200

    search-provider: cache only a limited number of equations

 search-provider/search-provider.vala | 9 +++++++++
 1 file changed, 9 insertions(+)
---
diff --git a/search-provider/search-provider.vala b/search-provider/search-provider.vala
index af2779e4..ea4036b9 100644
--- a/search-provider/search-provider.vala
+++ b/search-provider/search-provider.vala
@@ -16,10 +16,15 @@ public class SearchProvider : Object
     private unowned SearchProviderApp application;
     private Cancellable cancellable;
 
+    private const int MAX_CACHED_EQUATIONS = 10;
+    private Queue<string> queued_equations;
     private HashTable<string, string> cached_equations;
+
     public SearchProvider (SearchProviderApp app)
     {
         application = app;
+
+        queued_equations = new Queue<string> ();
         cached_equations = new HashTable<string, string> (str_hash, str_equal);
     }
 
@@ -114,8 +119,12 @@ public class SearchProvider : Object
             return false;
         }
 
+        queued_equations.push_tail (equation);
         cached_equations.insert (equation, result.strip ());
 
+        if (queued_equations.length > MAX_CACHED_EQUATIONS)
+            cached_equations.remove (queued_equations.pop_head ());
+
         return true;
     }
 


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