speed up #addAll:
authorStefan Vogel <sv@exept.de>
Wed, 21 Nov 2007 18:23:38 +0100
changeset 10797 5408c171f52f
parent 10796 08a9ee8cf317
child 10798 18d87b8fce50
speed up #addAll:
ArrayedCollection.st
--- a/ArrayedCollection.st	Wed Nov 21 11:10:11 2007 +0100
+++ b/ArrayedCollection.st	Wed Nov 21 18:23:38 2007 +0100
@@ -9,7 +9,6 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
-
 "{ Package: 'stx:libbasic' }"
 
 SequenceableCollection subclass:#ArrayedCollection
@@ -306,6 +305,30 @@
     ^ self == ArrayedCollection
 ! !
 
+!ArrayedCollection methodsFor:'adding'!
+
+addAll:aCollection
+    "add all elements of the argument, aCollection to the receiver.
+     Returns the argument, aCollection (sigh).
+
+     Redefined here, to perform only a single slow grow operation"
+
+    |mySize|
+
+    mySize := self size.
+    self grow:mySize + aCollection size.
+
+    aCollection do:[:element |
+        mySize := mySize + 1.
+        self at:mySize put:element
+    ].
+    ^ aCollection
+
+    "
+        #(1 2 3 4) addAll:#(5 6 7 8); yourself
+    "
+! !
+
 !ArrayedCollection methodsFor:'copying'!
 
 copyEmptyAndGrow:size
@@ -456,5 +479,5 @@
 !ArrayedCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ArrayedCollection.st,v 1.55 2006-01-31 22:27:02 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ArrayedCollection.st,v 1.56 2007-11-21 17:23:38 stefan Exp $'
 ! !