#TUNING by stefan
authorStefan Vogel <sv@exept.de>
Thu, 22 Sep 2016 13:19:33 +0200
changeset 20401 fb5b39df9894
parent 20400 644b7b8711f4
child 20402 005d199eb39b
#TUNING by stefan class: CachingRegistry comment/format in: #register:as: changed: #detect:ifNone:
CachingRegistry.st
--- 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.
             ].