#REFACTORING by stefan
class: WeakValueDictionary
changed:
#at:ifAbsent:
#at:ifAbsentPut:
#at:put:
#removeIdentityValue:ifAbsent:
#removeKey:ifAbsent:
#removeValue:ifAbsent:
--- a/WeakValueDictionary.st Tue Feb 12 12:57:55 2019 +0100
+++ b/WeakValueDictionary.st Tue Feb 12 20:41:00 2019 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1992 by Claus Gittinger
All Rights Reserved
@@ -74,8 +76,8 @@
] ifFalse:[
"do not use somethingRespondingToValue here, it might be a block answering
an integer and be therefore called twice"
- [
- ret := super at:key ifAbsent:0.
+ ret := [
+ super at:key ifAbsent:0.
] ensure:[
OperatingSystem unblockInterrupts.
].
@@ -85,6 +87,8 @@
ret := somethingRespondingToValue value
].
^ ret
+
+ "Modified: / 12-02-2019 / 20:35:30 / Stefan Vogel"
!
at:key ifAbsentPut:replacementBlock
@@ -103,8 +107,8 @@
"/ already blocked
val := super at:key ifAbsentPut:replacementBlock.
] ifFalse:[
- [
- val := super at:key ifAbsentPut:replacementBlock.
+ val := [
+ super at:key ifAbsentPut:replacementBlock.
] ensure:[
OperatingSystem unblockInterrupts.
].
@@ -115,6 +119,8 @@
].
^ val
+
+ "Modified: / 12-02-2019 / 20:35:51 / Stefan Vogel"
!
at:key put:anObject
@@ -123,8 +129,6 @@
Redefined to block interrupts, to avoid trouble when dependencies
are added within interrupting high prio processes."
- |val|
-
(anObject isNil or:[anObject class == SmallInteger]) ifTrue:[
self error:'WeakValueDictionary: invalid value'.
].
@@ -134,15 +138,15 @@
^ super at:key put:anObject.
].
- [
- val := super at:key put:anObject.
+ ^ [
+ super at:key put:anObject.
] ensure:[
OperatingSystem unblockInterrupts.
].
- ^ val
- "Modified: 6.5.1996 / 12:22:26 / stefan"
- "Modified: 29.1.1997 / 15:08:45 / cg"
+ "Modified: / 06-05-1996 / 12:22:26 / stefan"
+ "Modified: / 29-01-1997 / 15:08:45 / cg"
+ "Modified: / 12-02-2019 / 20:36:16 / Stefan Vogel"
!
removeIdentityValue:aValue ifAbsent:aBlock
@@ -154,24 +158,20 @@
Redefined to avoid synchronization problems, in case
of interrupts (otherwise, there could be some other operation
on the receiver done by another process, which garbles my contents)."
-
- |ret|
(aValue isNil or:[ aValue class == SmallInteger ]) ifTrue:[
^ aBlock value.
].
OperatingSystem blockInterrupts ifTrue:[
"/ already blocked
- ret := super removeIdentityValue:aValue ifAbsent:aBlock
- ] ifFalse:[
- [
- ret := super removeIdentityValue:aValue ifAbsent:aBlock
- ] ensure:[ OperatingSystem unblockInterrupts. ].
+ ^ super removeIdentityValue:aValue ifAbsent:aBlock
].
- ^ ret.
+
+ ^ [super removeIdentityValue:aValue ifAbsent:aBlock] ensure:[ OperatingSystem unblockInterrupts. ].
- "Created: 6.5.1996 / 14:47:37 / stefan"
- "Modified: 8.5.1996 / 14:54:09 / stefan"
+ "Created: / 06-05-1996 / 14:47:37 / stefan"
+ "Modified: / 08-05-1996 / 14:54:09 / stefan"
+ "Modified: / 12-02-2019 / 20:37:29 / Stefan Vogel"
!
removeKey:aKey ifAbsent:aBlock
@@ -190,8 +190,8 @@
"/ already blocked
ret := super removeKey:aKey ifAbsent:aBlock
] ifFalse:[
- [
- ret := super removeKey:aKey ifAbsent:aBlock
+ ret := [
+ super removeKey:aKey ifAbsent:aBlock
] ensure:[
OperatingSystem unblockInterrupts.
].
@@ -203,8 +203,9 @@
^ ret
- "Modified: 6.5.1996 / 12:44:07 / stefan"
- "Created: 6.5.1996 / 14:47:37 / stefan"
+ "Modified: / 06-05-1996 / 12:44:07 / stefan"
+ "Created: / 06-05-1996 / 14:47:37 / stefan"
+ "Modified: / 12-02-2019 / 20:38:07 / Stefan Vogel"
!
removeValue:aValue ifAbsent:aBlock
@@ -217,27 +218,19 @@
of interrupts (otherwise, there could be some other operation
on the receiver done by another process, which garbles my contents)."
- |ret|
-
(aValue isNil or:[aValue class == SmallInteger]) ifTrue:[
^ aBlock value.
].
OperatingSystem blockInterrupts ifTrue:[
"/ already blocked
- ret := super removeValue:aValue ifAbsent:aBlock
- ] ifFalse:[
- [
- ret := super removeValue:aValue ifAbsent:aBlock
- ] ensure:[
- OperatingSystem unblockInterrupts.
- ].
+ ^ super removeValue:aValue ifAbsent:aBlock
].
-
- ^ ret.
+ ^ [super removeValue:aValue ifAbsent:aBlock] ensure:[OperatingSystem unblockInterrupts].
- "Created: 6.5.1996 / 14:47:37 / stefan"
- "Modified: 8.5.1996 / 14:54:09 / stefan"
+ "Created: / 06-05-1996 / 14:47:37 / stefan"
+ "Modified: / 08-05-1996 / 14:54:09 / stefan"
+ "Modified: / 12-02-2019 / 20:39:44 / Stefan Vogel"
! !
!WeakValueDictionary methodsFor:'element disposal'!