#interests & #weakDependents always return a collection
authorClaus Gittinger <cg@exept.de>
Fri, 30 Jan 1998 14:22:55 +0100
changeset 3254 40b21297d9ab
parent 3253 735ed6008eef
child 3255 eb76cba071a1
#interests & #weakDependents always return a collection (no longer need to check for being nil if doing a #do:)
Object.st
--- a/Object.st	Fri Jan 30 12:32:34 1998 +0100
+++ b/Object.st	Fri Jan 30 14:22:55 1998 +0100
@@ -2254,11 +2254,11 @@
                 ]
     ].
     nwDeps := self nonWeakDependents.
-    (nwDeps notNil and:[nwDeps ~~ deps]) ifTrue:[
+    (nwDeps ~~ deps and:[nwDeps size ~~ 0]) ifTrue:[
         nwDeps do:aBlock 
     ].
 
-    "Modified: / 26.1.1998 / 11:24:34 / cg"
+    "Modified: / 30.1.1998 / 14:03:40 / cg"
 !
 
 myDependents
@@ -2347,45 +2347,46 @@
 
     wasBlocked := OperatingSystem blockInterrupts.
     [
-	|deps dep|
-
-	deps := self nonWeakDependents.
-
-	"/ to save a fair amount of memory in case of
-	"/ many dependencies, we store a single dependent in
-	"/ an Array, and switch to a Set if more dependents are
-	"/ added.
-
-	deps isNil ifTrue:[
-	    self nonWeakDependents:(Array with:anObject)
-	] ifFalse:[
-	    deps class == Array ifTrue:[
-		dep := deps at:1.
-		dep ~~ anObject ifTrue:[
-		    self nonWeakDependents:(IdentitySet with:dep with:anObject)
-		]
-	    ] ifFalse:[
-		deps add:anObject
-	    ]
-	]
+        |deps dep|
+
+        deps := self nonWeakDependents.
+
+        "/ to save a fair amount of memory in case of
+        "/ many dependencies, we store a single dependent in
+        "/ an Array, and switch to a Set if more dependents are
+        "/ added.
+
+        deps size == 0 ifTrue:[
+            self nonWeakDependents:(Array with:anObject)
+        ] ifFalse:[
+            deps class == Array ifTrue:[
+                dep := deps at:1.
+                dep ~~ anObject ifTrue:[
+                    self nonWeakDependents:(IdentitySet with:dep with:anObject)
+                ]
+            ] ifFalse:[
+                deps add:anObject
+            ]
+        ]
     ] valueNowOrOnUnwindDo:[
-	wasBlocked ifFalse:[
-	    OperatingSystem unblockInterrupts
-	]
+        wasBlocked ifFalse:[
+            OperatingSystem unblockInterrupts
+        ]
     ]
 
-    "Created: 19.4.1996 / 10:54:08 / cg"
-    "Modified: 1.8.1996 / 14:22:12 / cg"
+    "Created: / 19.4.1996 / 10:54:08 / cg"
+    "Modified: / 30.1.1998 / 14:03:08 / cg"
 !
 
 nonWeakDependents
-    "return a Collection of nonWeakDependents - nil if there is none.
+    "return a Collection of nonWeakDependents - empty if there is none.
      This is a private mechanism for directed dependencies."
 
-    NonWeakDependencies isNil ifTrue:[^nil].
-    ^ NonWeakDependencies at:self ifAbsent:[nil]
-
-    "Created: 19.4.1996 / 10:55:06 / cg"
+    NonWeakDependencies isNil ifTrue:[^ #()].
+    ^ NonWeakDependencies at:self ifAbsent:#()
+
+    "Created: / 19.4.1996 / 10:55:06 / cg"
+    "Modified: / 30.1.1998 / 14:06:47 / cg"
 !
 
 nonWeakDependents:aCollection
@@ -2416,33 +2417,33 @@
 
     wasBlocked := OperatingSystem blockInterrupts.
     [
-	|deps n|
-
-	deps := self nonWeakDependents.
-	deps notNil ifTrue:[
-	    deps class == Array ifTrue:[
-		(deps at:1) == anObject ifTrue:[
-		    self nonWeakDependents:nil
-		]
-	    ] ifFalse:[
-		deps remove:anObject ifAbsent:[].
-		(n := deps size) == 0 ifTrue:[
-		    self nonWeakDependents:nil
-		] ifFalse:[
-		    n == 1 ifTrue:[
-			self nonWeakDependents:(Array with:(deps first))
-		    ]
-		]
-	    ]
-	]
+        |deps n|
+
+        deps := self nonWeakDependents.
+        deps size ~~ 0 ifTrue:[
+            deps class == Array ifTrue:[
+                (deps at:1) == anObject ifTrue:[
+                    self nonWeakDependents:nil
+                ]
+            ] ifFalse:[
+                deps remove:anObject ifAbsent:[].
+                (n := deps size) == 0 ifTrue:[
+                    self nonWeakDependents:nil
+                ] ifFalse:[
+                    n == 1 ifTrue:[
+                        self nonWeakDependents:(Array with:(deps first))
+                    ]
+                ]
+            ]
+        ]
     ] valueNowOrOnUnwindDo:[
-	wasBlocked ifFalse:[
-	    OperatingSystem unblockInterrupts
-	]
+        wasBlocked ifFalse:[
+            OperatingSystem unblockInterrupts
+        ]
     ]
 
-    "Created: 19.4.1996 / 11:44:44 / cg"
-    "Modified: 19.7.1996 / 12:42:08 / cg"
+    "Created: / 19.4.1996 / 11:44:44 / cg"
+    "Modified: / 30.1.1998 / 14:04:01 / cg"
 ! !
 
 !Object methodsFor:'displaying'!
@@ -3116,12 +3117,36 @@
 !
 
 interests
-    "return a Collection of interests - nil if there is none.
+    "return a Collection of interests - empty if there is none.
      Here, we use the nonWeakDependents for interests."
 
     ^ self nonWeakDependents
 
-    "Created: 14.10.1996 / 22:20:51 / stefan"
+    "Created: / 14.10.1996 / 22:20:51 / stefan"
+    "Modified: / 30.1.1998 / 14:07:35 / cg"
+!
+
+interestsFor:someOne
+    "return a collection of interests of someOne - empty if there is none."
+
+    |coll deps|
+
+    deps := self interests.
+    deps size == 0 ifTrue:[^ #()].
+
+    coll := IdentitySet new.
+
+    deps do:[:dep |
+        (dep isMemberOf:InterestConverter) ifTrue:[
+            dep destination == someOne ifTrue:[
+                coll add:dep.
+            ]
+        ]
+    ].
+    ^ coll
+
+    "Created: / 30.1.1998 / 14:02:26 / cg"
+    "Modified: / 30.1.1998 / 14:08:24 / cg"
 !
 
 onChangeSend:aSelector to:anObject
@@ -3188,20 +3213,27 @@
     "/ for now, remove the interestConverter.
     "/ In the future, a more intelligent DependencyCollection class is planned for
 
-    |deps|
+    "/ cannot removeDependent within the loop - the collection rehashes
+
+    |deps coll|
 
     deps := self interests.
-    deps notNil ifTrue:[
-	deps do:[:dep |
-	    (dep isMemberOf:InterestConverter) ifTrue:[
-		dep destination == someOne ifTrue:[
-		    dep aspect == aspect ifTrue:[
-			self removeInterest:dep.
-			^ self
-		    ]
-		]
-	    ]
-	]
+    deps size ~~ 0 ifTrue:[
+        coll := IdentitySet new.
+
+        deps do:[:dep |
+            (dep isMemberOf:InterestConverter) ifTrue:[
+                dep destination == someOne ifTrue:[
+                    dep aspect == aspect ifTrue:[
+                        self removeInterest:dep.
+                        ^ self
+                    ]
+                ]
+            ]
+        ].
+        coll do:[:dep |
+            self removeInterest:dep.
+        ].
     ].
 
 
@@ -3258,9 +3290,9 @@
      Transcript cr.
     "
 
-    "Created: 19.4.1996 / 10:27:11 / cg"
-    "Modified: 19.4.1996 / 12:29:52 / cg"
-    "Modified: 14.10.1996 / 22:21:19 / stefan"
+    "Created: / 19.4.1996 / 10:27:11 / cg"
+    "Modified: / 14.10.1996 / 22:21:19 / stefan"
+    "Modified: / 30.1.1998 / 14:05:34 / cg"
 !
 
 retractInterestsFor:someOne
@@ -3274,22 +3306,22 @@
 
     "/ cannot removeDependent within the loop - the collection rehashes
 
-    coll := IdentitySet new.
-
     deps := self interests.
-    deps notNil ifTrue:[
-	deps do:[:dep |
-	    (dep isMemberOf:InterestConverter) ifTrue:[
-		dep destination == someOne ifTrue:[
-		    coll add:dep.
-		]
-	    ]
-	].
+    deps size ~~ 0 ifTrue:[
+        coll := IdentitySet new.
+
+        deps do:[:dep |
+            (dep isMemberOf:InterestConverter) ifTrue:[
+                dep destination == someOne ifTrue:[
+                    coll add:dep.
+                ]
+            ]
+        ].
+        coll do:[:dep |
+            self removeInterest:dep.
+        ].
     ].
 
-    coll do:[:dep |
-	self removeInterest:dep.
-    ].
 
 
     "
@@ -3324,9 +3356,9 @@
      Transcript cr.
     "
 
-    "Created: 19.4.1996 / 10:23:46 / cg"
-    "Modified: 19.4.1996 / 12:30:03 / cg"
-    "Modified: 14.10.1996 / 22:21:25 / stefan"
+    "Created: / 19.4.1996 / 10:23:46 / cg"
+    "Modified: / 14.10.1996 / 22:21:25 / stefan"
+    "Modified: / 30.1.1998 / 14:04:52 / cg"
 ! !
 
 !Object methodsFor:'interrupt handling'!
@@ -6412,6 +6444,6 @@
 !Object class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.220 1998-01-26 20:10:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.221 1998-01-30 13:22:55 cg Exp $'
 ! !
 Object initialize!