WeakValueDictionary.st
changeset 20164 7333519ac040
parent 20163 3855e97fe259
child 20165 529ce6e78617
--- a/WeakValueDictionary.st	Thu Jul 21 10:02:03 2016 +0200
+++ b/WeakValueDictionary.st	Thu Jul 21 11:28:47 2016 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1992 by Claus Gittinger
 	      All Rights Reserved
@@ -183,9 +181,17 @@
 
     |ret|
 
-    [
-	ret := super removeKey:aKey ifAbsent:aBlock
-    ] valueUninterruptably.
+    OperatingSystem blockInterrupts ifTrue:[
+        "/ already blocked
+        ret := super removeKey:aKey ifAbsent:aBlock
+    ] ifFalse:[
+        [
+            ret := super removeKey:aKey ifAbsent:aBlock
+        ] ensure:[
+            OperatingSystem unblockInterrupts.
+        ].
+    ].
+
     ^ ret
 
     "Modified: 6.5.1996 / 12:44:07 / stefan"
@@ -204,9 +210,17 @@
 
     |ret|
 
-    [
-	ret := super removeValue:aKey ifAbsent:aBlock
-    ] valueUninterruptably.
+    OperatingSystem blockInterrupts ifTrue:[
+        "/ already blocked
+        ret := super removeValue:aKey ifAbsent:aBlock
+    ] ifFalse:[
+        [
+            ret := super removeValue:aKey ifAbsent:aBlock
+        ] ensure:[
+            OperatingSystem unblockInterrupts.
+        ].
+    ].
+
     ^ ret.
 
     "Created: 6.5.1996 / 14:47:37 / stefan"
@@ -303,12 +317,17 @@
     "redefined to block interrupts
      (avoid change of the dictionary while accessing)"
 
-    |val|
+    |ret wasBlocked|
 
-    [
-	val := super includes:anObject.
-    ] valueUninterruptably.
-    ^ val
+    anObject class == SmallInteger ifTrue:[
+        "Integers cannot be stored into a WeakValueDictionary"
+        ^ false.
+    ].
+
+    wasBlocked := OperatingSystem blockInterrupts.
+    ret := super includes:anObject.
+    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+     ^ ret
 
     "Modified: 6.5.1996 / 12:22:26 / stefan"
     "Modified: 1.7.1997 / 10:45:52 / cg"
@@ -318,7 +337,7 @@
 includesKey:key
     "redefined to check for already collected values"
 
-    ^ (self at:key ifAbsent:0) ~~ 0.
+    ^ (self at:key ifAbsent:DeletedEntry) ~~ DeletedEntry.
 
     "Modified: 6.5.1996 / 12:22:26 / stefan"
     "Modified: 1.7.1997 / 10:45:52 / cg"