Do not add nil elements to a Set in #asSet and #asIdentitySet
authorStefan Vogel <sv@exept.de>
Wed, 21 Nov 2007 11:10:11 +0100
changeset 10796 08a9ee8cf317
parent 10795 3797cbc3fcb4
child 10797 5408c171f52f
Do not add nil elements to a Set in #asSet and #asIdentitySet
Array.st
--- a/Array.st	Wed Nov 21 11:10:09 2007 +0100
+++ b/Array.st	Wed Nov 21 11:10:11 2007 +0100
@@ -278,6 +278,7 @@
     "Modified: 23.4.1996 / 15:55:06 / cg"
 ! !
 
+
 !Array methodsFor:'accessing'!
 
 at:index
@@ -507,6 +508,28 @@
 
 !Array methodsFor:'enumerating'!
 
+addAllNonNilElementsTo:aCollection
+    "add all nonNil elements of the receiver to aCollection.
+     Return aCollection.
+     Redefined here for slightly more speed."
+
+    |stop "{ Class: SmallInteger }"|
+
+    stop := self size.
+    1 to:stop do:[:idx |
+        |each|
+        each := self at:idx.
+        each notNil ifTrue:[
+            aCollection add:each.
+        ].
+    ].
+    ^ aCollection
+
+    "
+     #(1 2 3 4 5 1 2 3 symbol 'string' nil) addAllNonNilElementsTo:Set new
+    "
+!
+
 addAllTo:aCollection
     "add all elements of the receiver to aCollection.
      Return aCollection.
@@ -2496,5 +2519,5 @@
 !Array class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.142 2006-10-13 11:01:35 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.143 2007-11-21 10:10:11 stefan Exp $'
 ! !