CachingRegistry.st
branchjv
changeset 20578 39641ba8d6e0
parent 20577 a27e7b3031cb
parent 20435 54505346a337
child 20727 fb8c5591428b
--- a/CachingRegistry.st	Tue Sep 20 11:37:33 2016 +0100
+++ b/CachingRegistry.st	Mon Oct 03 12:44:41 2016 +0100
@@ -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 // 4) 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.
             ].