care for empty WeakSet which says its not
authorClaus Gittinger <cg@exept.de>
Fri, 24 Jan 1997 21:58:45 +0100
changeset 2261 61096f935f76
parent 2260 96d898c2874d
child 2262 4c4d810f006f
care for empty WeakSet which says its not
WeakDepDict.st
WeakDependencyDictionary.st
--- a/WeakDepDict.st	Fri Jan 24 21:54:29 1997 +0100
+++ b/WeakDepDict.st	Fri Jan 24 21:58:45 1997 +0100
@@ -55,7 +55,7 @@
     "special entry for dependency management:
      remove any empty (due to finalization) value WeakArray elements."
 
-    |index t wasBlocked val|
+    |index t wasBlocked deps o|
 
     "/ careful: this is sent by the finalizer at low prio.
     "/ be prepared for the receiver to change while we walk over
@@ -67,12 +67,12 @@
 
         wasBlocked := OperatingSystem blockInterrupts.
         index <= keyArray size ifTrue:[
-            val := valueArray basicAt:index.
-            val notNil ifTrue:[
+            deps := valueArray basicAt:index.
+            deps notNil ifTrue:[
                 "/ is it an empty WeakArray ?
 
-                (val isMemberOf:WeakArray) ifTrue:[
-                    t := val findFirst:[:el | el notNil and:[el ~~ 0]].
+                (deps isMemberOf:WeakArray) ifTrue:[
+                    t := deps findFirst:[:el | el notNil and:[el ~~ 0]].
                     t == 0 ifTrue:[
                         "/ yes - nil it
                         valueArray basicAt:index put:nil.
@@ -84,8 +84,8 @@
                 ] ifFalse:[
                    "/ is it an empty WeakIdSet ?
 
-                   (val isMemberOf:WeakIdentitySet) ifTrue:[
-                        (t := val size) == 0 ifTrue:[
+                   (deps isMemberOf:WeakIdentitySet) ifTrue:[
+                        (t := deps size) == 0 ifTrue:[
                             "/ yes - nil it
                             valueArray basicAt:index put:nil.
                             (keyArray basicAt:index) notNil ifTrue:[
@@ -94,9 +94,13 @@
                             ]
                         ] ifFalse:[
                             t == 1 ifTrue:[
-                                "/ the set lost an object, and shrunk to size 1
-                                "/ can now use a WeakArray
-                                valueArray basicAt:index put:(WeakArray with:val first)
+                                "/ careful - it could actually be empty
+                                o := deps firstIfEmpty:nil.
+                                o notNil ifTrue:[
+                                    "/ the set lost an object, and shrunk to size 1
+                                    "/ can now use a WeakArray
+                                    valueArray basicAt:index put:(WeakArray with:o)
+                                ]
                             ]
                         ]
                     ]
@@ -112,12 +116,12 @@
      Dependencies removeEmptyDependencyValues
     "
 
-    "Modified: 8.1.1997 / 23:57:56 / cg"
     "Created: 9.1.1997 / 00:00:28 / cg"
+    "Modified: 24.1.1997 / 21:57:31 / cg"
 ! !
 
 !WeakDependencyDictionary class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/WeakDepDict.st,v 1.2 1997-01-09 00:31:33 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/WeakDepDict.st,v 1.3 1997-01-24 20:58:45 cg Exp $'
 ! !
--- a/WeakDependencyDictionary.st	Fri Jan 24 21:54:29 1997 +0100
+++ b/WeakDependencyDictionary.st	Fri Jan 24 21:58:45 1997 +0100
@@ -55,7 +55,7 @@
     "special entry for dependency management:
      remove any empty (due to finalization) value WeakArray elements."
 
-    |index t wasBlocked val|
+    |index t wasBlocked deps o|
 
     "/ careful: this is sent by the finalizer at low prio.
     "/ be prepared for the receiver to change while we walk over
@@ -67,12 +67,12 @@
 
         wasBlocked := OperatingSystem blockInterrupts.
         index <= keyArray size ifTrue:[
-            val := valueArray basicAt:index.
-            val notNil ifTrue:[
+            deps := valueArray basicAt:index.
+            deps notNil ifTrue:[
                 "/ is it an empty WeakArray ?
 
-                (val isMemberOf:WeakArray) ifTrue:[
-                    t := val findFirst:[:el | el notNil and:[el ~~ 0]].
+                (deps isMemberOf:WeakArray) ifTrue:[
+                    t := deps findFirst:[:el | el notNil and:[el ~~ 0]].
                     t == 0 ifTrue:[
                         "/ yes - nil it
                         valueArray basicAt:index put:nil.
@@ -84,8 +84,8 @@
                 ] ifFalse:[
                    "/ is it an empty WeakIdSet ?
 
-                   (val isMemberOf:WeakIdentitySet) ifTrue:[
-                        (t := val size) == 0 ifTrue:[
+                   (deps isMemberOf:WeakIdentitySet) ifTrue:[
+                        (t := deps size) == 0 ifTrue:[
                             "/ yes - nil it
                             valueArray basicAt:index put:nil.
                             (keyArray basicAt:index) notNil ifTrue:[
@@ -94,9 +94,13 @@
                             ]
                         ] ifFalse:[
                             t == 1 ifTrue:[
-                                "/ the set lost an object, and shrunk to size 1
-                                "/ can now use a WeakArray
-                                valueArray basicAt:index put:(WeakArray with:val first)
+                                "/ careful - it could actually be empty
+                                o := deps firstIfEmpty:nil.
+                                o notNil ifTrue:[
+                                    "/ the set lost an object, and shrunk to size 1
+                                    "/ can now use a WeakArray
+                                    valueArray basicAt:index put:(WeakArray with:o)
+                                ]
                             ]
                         ]
                     ]
@@ -112,12 +116,12 @@
      Dependencies removeEmptyDependencyValues
     "
 
-    "Modified: 8.1.1997 / 23:57:56 / cg"
     "Created: 9.1.1997 / 00:00:28 / cg"
+    "Modified: 24.1.1997 / 21:57:31 / cg"
 ! !
 
 !WeakDependencyDictionary class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/WeakDependencyDictionary.st,v 1.2 1997-01-09 00:31:33 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/WeakDependencyDictionary.st,v 1.3 1997-01-24 20:58:45 cg Exp $'
 ! !