CachingRegistry.st
changeset 20401 fb5b39df9894
parent 20395 50417882857e
child 20435 54505346a337
--- a/CachingRegistry.st	Thu Sep 22 11:28:27 2016 +0200
+++ b/CachingRegistry.st	Thu Sep 22 13:19:33 2016 +0200
@@ -76,9 +76,28 @@
 detect:aBlock ifNone:exceptionValue
     "... additionaly move it to the front of the LRU chain"
 
+    |cnt|
+
+    "first a quick lookup 
+     (most recent entry is at the end, because #removeIdentical makes room at the end)..."
+
+    cnt := 1.
+    keptReferences reverseDo:[:obj|
+        (aBlock value:obj) ifTrue:[
+            "if not at the end, put it to the end.
+             but avoid to much remove/add actions"
+            cnt > (cacheSize // 2) ifTrue:[
+                keptReferences removeIdentical:obj ifAbsent:[].
+                keptReferences addLast:obj.
+            ].
+            ^ obj
+        ].
+        cnt := cnt + 1.
+    ].
+
+    "check the whole registry..."
     keyArray validElementsDo:[:obj |
         (obj ~~ DeletedEntry and:[aBlock value:obj]) ifTrue:[
-            keptReferences removeIdentical:obj ifAbsent:[].
             keptReferences size >= cacheSize ifTrue:[
                 keptReferences removeFirst.
             ].