#REFACTORING by stefan
class: CachingRegistry
refactored because registry now inherits from WeakIdentityDictionary
--- a/CachingRegistry.st Tue Jun 28 11:07:21 2016 +0200
+++ b/CachingRegistry.st Tue Jun 28 11:07:29 2016 +0200
@@ -9,8 +9,9 @@
other person. No title to or ownership of the software is
hereby transferred.
"
+"{ Package: 'stx:libbasic' }"
-"{ Package: 'stx:libbasic' }"
+"{ NameSpace: Smalltalk }"
Registry subclass:#CachingRegistry
instanceVariableNames:'keptReferences cacheSize'
@@ -42,7 +43,7 @@
However, it keeps hard references to the last n registered objects,
preventing them from being garbage collected (and finalized).
This is useful for resources, which do not cost too much memory,
- but are expensive to allocate - a special canditate of this kind are
+ but are expensive to allocate - a special candidate of this kind are
XFonts. With a CachingRegistry, fonts are kept a bit longer alive
and can therefore often be reused - even if temporarily unreferenced.
@@ -50,13 +51,13 @@
[author:]
- Claus Gittinger (cg@exept)
+ Claus Gittinger (cg@exept)
[see also:]
[instance variables:]
- keptObjects Collection hard referenced objects
- cacheSize Integer number of hard references
+ keptObjects Collection hard referenced objects
+ cacheSize Integer number of hard references
[class variables:]
"
@@ -73,25 +74,28 @@
register:anObject as:aHandle
keptReferences removeIdentical:anObject ifAbsent:nil.
- keptReferences addLast:anObject.
- keptReferences size > cacheSize ifTrue:[
- keptReferences removeFirst.
+ aHandle notNil ifTrue:[
+ keptReferences addLast:anObject.
+ keptReferences size > cacheSize ifTrue:[
+ keptReferences removeFirst.
+ ].
].
super register:anObject as:aHandle.
!
-repairTally
- keptReferences := OrderedCollection new:cacheSize.
- super repairTally.
+removeKey:anObject ifAbsent:absentBlock
+ keptReferences removeIdentical:anObject ifAbsent:nil.
+ super removeKey:anObject ifAbsent:absentBlock.
!
-unregister:anObject atIndex:index
+safeRemoveKey:anObject
keptReferences removeIdentical:anObject ifAbsent:nil.
- super unregister:anObject atIndex:index.
+ super safeRemoveKey:anObject.
! !
!CachingRegistry class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/CachingRegistry.st,v 1.2 2015-04-21 16:01:16 cg Exp $'
+ ^ '$Header$'
! !
+