added #contents:
authorClaus Gittinger <cg@exept.de>
Wed, 23 Aug 2000 18:18:04 +0200
changeset 908 f628a3c801ca
parent 907 4ef63236d698
child 909 c4f759a283cf
added #contents:
List.st
--- a/List.st	Tue Aug 22 16:02:25 2000 +0200
+++ b/List.st	Wed Aug 23 18:18:04 2000 +0200
@@ -11,6 +11,8 @@
 "
 
 
+"{ Package: 'stx:libbasic2' }"
+
 OrderedCollection subclass:#List
 	instanceVariableNames:'dependents'
 	classVariableNames:''
@@ -353,6 +355,54 @@
 
 !List methodsFor:'filling & replacing'!
 
+contents:aCollection
+    "replace all elements in the receiver by aCollection,
+     Redefined - can be done faster"
+
+     |oldSize newSize|
+
+     oldSize := self size.
+     newSize := aCollection size.
+
+     newSize < oldSize ifTrue:[
+        self replaceFrom:1 to:newSize with:aCollection startingAt:1.
+        self removeFromIndex:newSize+1 toIndex:oldSize.
+     ] ifFalse:[
+        newSize > oldSize ifTrue:[
+            super grow:newSize.
+            self replaceFrom:1 to:oldSize with:aCollection startingAt:1.
+            self replaceFrom:oldSize+1 to:newSize with:aCollection startingAt:oldSize+1.
+        ] ifFalse:[
+            self replaceFrom:1 to:newSize with:aCollection startingAt:1.
+        ]
+     ].
+
+     "
+      |l|
+      l := List new.
+      l contents:#(1 2 3 4 5).
+      l        
+
+      |l|
+      l := List new.
+      l addAll:#(1 2 3 4 5).
+      l contents:#(10 20 30).
+      l       
+
+      |l|
+      l := List new.
+      l addAll:#(1 2 3 4 5).
+      l contents:#(10 20 30 40 50 60 70 80).
+      l      
+
+      |l|
+      l := List new.
+      l addAll:#(1 2 3 4 5).
+      l contents:#(10 20 30 40 50).
+      l      
+     "
+!
+
 replaceFrom:start to:stop with:aCollection startingAt:repStart
     "replace elements in the receiver between index start and stop,
      with elements  taken from replacementCollection starting at repStart.
@@ -381,5 +431,5 @@
 !List class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/List.st,v 1.17 2000-02-11 13:32:32 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/List.st,v 1.18 2000-08-23 16:18:04 cg Exp $'
 ! !