72 !WeakIdentitySet class methodsFor:'queries'! |
72 !WeakIdentitySet class methodsFor:'queries'! |
73 |
73 |
74 goodSizeFrom:arg |
74 goodSizeFrom:arg |
75 "return a good array size for the given argument. |
75 "return a good array size for the given argument. |
76 Since WeakIdentitySets are mostly used for dependency management, we typically |
76 Since WeakIdentitySets are mostly used for dependency management, we typically |
77 have only one element in the set. Therefore use exact size for small sets |
77 have only a small number of elements in the set. |
|
78 Therefore use exact size for small sets |
78 (instead of rounding up to the prime 11)." |
79 (instead of rounding up to the prime 11)." |
79 |
80 |
80 arg <= 10 ifTrue:[ |
81 arg <= 10 ifTrue:[ |
81 arg < 1 ifTrue:[^ 1]. |
82 arg < 1 ifTrue:[^ 1]. |
82 ^ arg. |
83 ^ arg. |
83 ]. |
84 ]. |
84 ^ super goodSizeFrom:arg |
85 ^ super goodSizeFrom:arg |
85 ! ! |
86 ! ! |
86 |
87 |
|
88 !WeakIdentitySet methodsFor:'accessing'! |
|
89 |
|
90 firstIfEmpty:exceptionValue |
|
91 "return the first element of the collection or the |
|
92 value of the exceptionBlock, if empty. |
|
93 Redefine, since the inherited method does not work if |
|
94 elements change silently to nil" |
|
95 |
|
96 |index "{ Class: SmallInteger }" |
|
97 element| |
|
98 |
|
99 index := 1. |
|
100 [index <= keyArray size] whileTrue:[ |
|
101 element := keyArray basicAt:index. |
|
102 element notNil ifTrue:[ |
|
103 element ~~ 0 ifTrue:[ |
|
104 element ~~ DeletedEntry ifTrue:[ |
|
105 ^ element |
|
106 ] |
|
107 ] |
|
108 ]. |
|
109 index := index + 1 |
|
110 ]. |
|
111 |
|
112 ^ exceptionValue value. |
|
113 ! ! |
|
114 |
87 !WeakIdentitySet methodsFor:'adding & removing'! |
115 !WeakIdentitySet methodsFor:'adding & removing'! |
88 |
116 |
89 add:newElement |
117 add:newElement |
90 "redefined to avoid synchronization promlems, in case |
118 "redefined to avoid synchronization problems, in case of interrupts |
91 of interrupts |
119 (otherwise, there could be some other operation on the receiver |
|
120 done by another process, which garbles my contents)" |
|
121 |
|
122 |ret| |
|
123 |
|
124 (OperatingSystem blockInterrupts) ifTrue:[ |
|
125 "/ already blocked |
|
126 ^ super add:newElement. |
|
127 ]. |
|
128 |
|
129 [ |
|
130 ret := super add:newElement. |
|
131 ] valueNowOrOnUnwindDo:[ |
|
132 OperatingSystem unblockInterrupts |
|
133 ]. |
|
134 ^ ret |
|
135 |
|
136 "Modified: 29.1.1997 / 15:06:57 / cg" |
|
137 ! |
|
138 |
|
139 remove:anObject ifAbsent:exceptionBlock |
|
140 "redefined to avoid synchronization problems, in case of interrupts |
92 (otherwise, there could be some other operation on the receiver |
141 (otherwise, there could be some other operation on the receiver |
93 done by another process, which garbles my contents)" |
142 done by another process, which garbles my contents)" |
94 |
143 |
95 |wasBlocked| |
144 |ret| |
96 |
145 |
97 wasBlocked := OperatingSystem blockInterrupts. |
146 (OperatingSystem blockInterrupts) ifTrue:[ |
|
147 "/ already blocked |
|
148 ^ super remove:anObject ifAbsent:exceptionBlock. |
|
149 ]. |
|
150 |
98 [ |
151 [ |
99 super add:newElement. |
152 ret := super remove:anObject ifAbsent:exceptionBlock |
100 ] valueNowOrOnUnwindDo:[ |
153 ] valueNowOrOnUnwindDo:[ |
101 wasBlocked ifFalse:[OperatingSystem unblockInterrupts] |
154 OperatingSystem unblockInterrupts |
102 ] |
155 ]. |
103 |
156 ^ ret |
104 "Modified: 20.10.1996 / 14:04:29 / cg" |
157 |
105 ! |
158 "Modified: 29.1.1997 / 15:07:19 / cg" |
106 |
|
107 remove:anObject ifAbsent:exceptionBlock |
|
108 "redefined to avoid synchronization problems, in case |
|
109 of interrupts |
|
110 (otherwise, there could be some other operation on the receiver |
|
111 done by another process, which garbles my contents)" |
|
112 |
|
113 |wasBlocked| |
|
114 |
|
115 wasBlocked := OperatingSystem blockInterrupts. |
|
116 [ |
|
117 super remove:anObject ifAbsent:exceptionBlock |
|
118 ] valueNowOrOnUnwindDo:[ |
|
119 wasBlocked ifFalse:[OperatingSystem unblockInterrupts] |
|
120 ] |
|
121 |
|
122 "Modified: 1.3.1996 / 21:16:10 / cg" |
|
123 ! ! |
159 ! ! |
124 |
160 |
125 !WeakIdentitySet methodsFor:'element disposal'! |
161 !WeakIdentitySet methodsFor:'element disposal'! |
126 |
162 |
127 update:something with:aParameter from:changedObject |
163 update:something with:aParameter from:changedObject |