74 !CachingRegistry methodsFor:'enumerating'! |
74 !CachingRegistry methodsFor:'enumerating'! |
75 |
75 |
76 detect:aBlock ifNone:exceptionValue |
76 detect:aBlock ifNone:exceptionValue |
77 "... additionaly move it to the front of the LRU chain" |
77 "... additionaly move it to the front of the LRU chain" |
78 |
78 |
|
79 |cnt| |
|
80 |
|
81 "first a quick lookup |
|
82 (most recent entry is at the end, because #removeIdentical makes room at the end)..." |
|
83 |
|
84 cnt := 1. |
|
85 keptReferences reverseDo:[:obj| |
|
86 (aBlock value:obj) ifTrue:[ |
|
87 "if not at the end, put it to the end. |
|
88 but avoid to much remove/add actions" |
|
89 cnt > (cacheSize // 2) ifTrue:[ |
|
90 keptReferences removeIdentical:obj ifAbsent:[]. |
|
91 keptReferences addLast:obj. |
|
92 ]. |
|
93 ^ obj |
|
94 ]. |
|
95 cnt := cnt + 1. |
|
96 ]. |
|
97 |
|
98 "check the whole registry..." |
79 keyArray validElementsDo:[:obj | |
99 keyArray validElementsDo:[:obj | |
80 (obj ~~ DeletedEntry and:[aBlock value:obj]) ifTrue:[ |
100 (obj ~~ DeletedEntry and:[aBlock value:obj]) ifTrue:[ |
81 keptReferences removeIdentical:obj ifAbsent:[]. |
|
82 keptReferences size >= cacheSize ifTrue:[ |
101 keptReferences size >= cacheSize ifTrue:[ |
83 keptReferences removeFirst. |
102 keptReferences removeFirst. |
84 ]. |
103 ]. |
85 keptReferences addLast:obj. |
104 keptReferences addLast:obj. |
86 ^ obj |
105 ^ obj |