WeakDependencyDictionary.st
changeset 2316 6b24c092456a
parent 2300 789e1dd0a0b7
child 2508 32924c15a4cd
--- a/WeakDependencyDictionary.st	Wed Jan 29 22:10:56 1997 +0100
+++ b/WeakDependencyDictionary.st	Wed Jan 29 22:11:16 1997 +0100
@@ -69,7 +69,7 @@
     "special entry for dependency management:
      remove any empty (due to finalization) value WeakArray elements."
 
-    |index t wasBlocked deps o key b|
+    |index t wasBlocked deps o key b originalKeyArray|
 
     "/ careful: this is sent by the finalizer at low prio.
     "/ be prepared for the receiver to change while we walk over
@@ -79,64 +79,72 @@
 
     b := [:el | el notNil and:[el ~~ 0]].
 
+    originalKeyArray := keyArray.
+
     index := 1.
     [index <= keyArray size] whileTrue:[
         "/ get the size again - it could have changed
 
         wasBlocked := OperatingSystem blockInterrupts.
 
+        keyArray ~~ originalKeyArray ifTrue:[
+            index := 1. "/ start over
+            'restart removeEmpty' printCR.
+            originalKeyArray := keyArray.
+        ].
+
         index <= keyArray size ifTrue:[
             key := keyArray basicAt:index.
             key == 0 ifTrue:[
-                key := nil.
+                "/ that one is gone
+                key := DeletedEntry.
+                keyArray basicAt:index put:key.
+                valueArray basicAt:index put:nil.
+                tally := tally - 1.
             ].
 
-            deps := valueArray basicAt:index.
-            deps notNil ifTrue:[
-                "/ is it an empty WeakArray ?
+            (key notNil and:[key ~~ DeletedEntry]) ifTrue:[
+                deps := valueArray basicAt:index.
+                deps notNil ifTrue:[
+                    "/ is it an empty WeakArray ?
 
-                (deps isMemberOf:WeakArray) ifTrue:[
-                    t := deps findFirst:b.
-                    t == 0 ifTrue:[
-                        "/ yes - nil it
-                        valueArray basicAt:index put:nil.
-                        key notNil ifTrue:[
+                    (deps isMemberOf:WeakArray) ifTrue:[
+                        t := deps findFirst:b.
+                        t == 0 ifTrue:[
+                            "/ yes - nil it
+                            valueArray basicAt:index put:nil.
                             keyArray basicAt:index put:DeletedEntry.
                             tally := tally - 1.
                         ]
+                    ] ifFalse:[
+                       "/ is it an empty WeakIdSet ?
+
+                       (deps isMemberOf:WeakIdentitySet) ifTrue:[
+                            (t := deps size) == 0 ifTrue:[
+                                "/ yes - nil it
+                                valueArray basicAt:index put:nil.
+                                keyArray basicAt:index put:DeletedEntry.
+                                tally := tally - 1.
+"/                            ] ifFalse:[
+"/                                t == 1 ifTrue:[
+"/                                    "/ 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)
+"/                                    ] ifFalse:[
+"/                                        key notNil ifTrue:[
+"/                                            keyArray basicAt:index put:DeletedEntry.
+"/                                            tally := tally - 1.
+"/                                        ]
+"/                                    ]
+"/                                ]
+                            ]
+                        ]
                     ]
                 ] ifFalse:[
-                   "/ is it an empty WeakIdSet ?
-
-                   (deps isMemberOf:WeakIdentitySet) ifTrue:[
-                        (t := deps size) == 0 ifTrue:[
-                            "/ yes - nil it
-                            valueArray basicAt:index put:nil.
-                            key notNil ifTrue:[
-                                keyArray basicAt:index put:DeletedEntry.
-                                tally := tally - 1.
-                            ]
-"/                        ] ifFalse:[
-"/                            t == 1 ifTrue:[
-"/                                "/ 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)
-"/                                ] ifFalse:[
-"/                                    key notNil ifTrue:[
-"/                                        keyArray basicAt:index put:DeletedEntry.
-"/                                        tally := tally - 1.
-"/                                    ]
-"/                                ]
-"/                            ]
-                        ]
-                    ]
-                ]
-            ] ifFalse:[
-                (key notNil and:[key ~~ DeletedEntry]) ifTrue:[
-                    'oops:' print. key printCR.
+                    'oops: nil value for key' print. key printCR.
                     keyArray basicAt:index put:DeletedEntry.
                     tally := tally - 1.
                 ]
@@ -153,11 +161,11 @@
     "
 
     "Created: 9.1.1997 / 00:00:28 / cg"
-    "Modified: 27.1.1997 / 15:54:28 / cg"
+    "Modified: 29.1.1997 / 22:02:33 / cg"
 ! !
 
 !WeakDependencyDictionary class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/WeakDependencyDictionary.st,v 1.7 1997-01-29 13:22:40 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/WeakDependencyDictionary.st,v 1.8 1997-01-29 21:11:16 cg Exp $'
 ! !