class: ArrayedCollection
authorClaus Gittinger <cg@exept.de>
Thu, 11 Dec 2014 18:08:43 +0100
changeset 17212 2e02d9d621da
parent 17211 19b94763ad16
child 17213 1031d5018042
class: ArrayedCollection category of: #grow: #removeAll
ArrayedCollection.st
--- a/ArrayedCollection.st	Thu Dec 11 18:07:37 2014 +0100
+++ b/ArrayedCollection.st	Thu Dec 11 18:08:43 2014 +0100
@@ -350,6 +350,30 @@
     "
         #(1 2 3 4) addAll:#(5 6 7 8); yourself
     "
+!
+
+removeAll
+    "{ Pragma: +optSpace }"
+
+    "remove all elements from the receiver. Returns the receiver.
+
+     For ArrayedCollections (which are actually fixed-size collections),
+     this is a slow operation, since a #become: is required to update
+     all owners. Better use a collection which is prepared for growing
+     (i.e. an OrderedCollection).
+     We output a warning message here, to remind you about that."
+
+    'ArrayedCollection [info]: slow removeAll operation (' infoPrint.
+    self class name infoPrint. ')' infoPrintCR.
+
+    self become:(self copyEmpty)
+
+    "
+     #(1 2 3 4 5) copy removeAll    
+     #(1 2 3 4 5) removeAll    
+    "
+
+    "Modified: 10.1.1997 / 15:14:55 / cg"
 ! !
 
 !ArrayedCollection methodsFor:'copying'!
@@ -383,6 +407,46 @@
     "Modified: 18.7.1996 / 21:39:09 / cg"
 ! !
 
+!ArrayedCollection methodsFor:'growing'!
+
+grow:newSize
+    "grow the receiver i.e. cut off everything after newSize.
+     Warning: this may be a slow operation due to the use of become 
+     - you should write your collection classes to avoid the use of become. 
+     You have been warned."
+
+    |newArray oldSize|
+
+    oldSize := self size.
+    (newSize ~~ oldSize) ifTrue:[
+        InfoPrinting ifTrue:[
+            "/
+            "/ output a warning - you should rewrite your application
+            "/ to use some collection which implements grow: more efficient
+            "/ (i.e. use OrderedCollection instead of Array ..)
+            "/
+            'ArrayedCollection [warning]: slow grow operation (' errorPrint.
+            self class name infoPrint. ') ' errorPrintCR.
+            Context showWhereWeCameFrom.
+        ].
+
+        newArray := self species new:newSize.
+        newArray replaceFrom:1 to:(newSize min:oldSize) with:self.
+        self become:newArray.
+    ]
+
+    "
+     #(1 2 3 4 5 6) add:7
+     #(1 2 3 4 5 6) remove:5 
+     #(1 2 3 4 5 6) copy grow:3  
+     #(1 2 3 4 5 6) copy grow:10  
+     'hello world' copy grow:5   
+     'hello' copy grow:20   
+    "
+
+    "Modified: 10.1.1997 / 15:14:43 / cg"
+! !
+
 
 !ArrayedCollection methodsFor:'printing & storing'!
 
@@ -435,73 +499,13 @@
     ^ OrderedCollection
 ! !
 
-!ArrayedCollection methodsFor:'resizing'!
-
-grow:newSize
-    "grow the receiver i.e. cut off everything after newSize.
-     Warning: this may be a slow operation due to the use of become 
-     - you should write your collection classes to avoid the use of become. 
-     You have been warned."
-
-    |newArray oldSize|
-
-    oldSize := self size.
-    (newSize ~~ oldSize) ifTrue:[
-        InfoPrinting ifTrue:[
-            "/
-            "/ output a warning - you should rewrite your application
-            "/ to use some collection which implements grow: more efficient
-            "/ (i.e. use OrderedCollection instead of Array ..)
-            "/
-            'ArrayedCollection [warning]: slow grow operation (' errorPrint.
-            self class name infoPrint. ') ' errorPrintCR.
-            Context showWhereWeCameFrom.
-        ].
-
-        newArray := self species new:newSize.
-        newArray replaceFrom:1 to:(newSize min:oldSize) with:self.
-        self become:newArray.
-    ]
-
-    "
-     #(1 2 3 4 5 6) add:7
-     #(1 2 3 4 5 6) remove:5 
-     #(1 2 3 4 5 6) copy grow:3  
-     #(1 2 3 4 5 6) copy grow:10  
-     'hello world' copy grow:5   
-     'hello' copy grow:20   
-    "
-
-    "Modified: 10.1.1997 / 15:14:43 / cg"
-!
-
-removeAll
-    "{ Pragma: +optSpace }"
-
-    "remove all elements from the receiver. Returns the receiver.
-
-     For ArrayedCollections (which are actually fixed-size collections),
-     this is a slow operation, since a #become: is required to update
-     all owners. Better use a collection which is prepared for growing
-     (i.e. an OrderedCollection).
-     We output a warning message here, to remind you about that."
-
-    'ArrayedCollection [info]: slow removeAll operation (' infoPrint.
-    self class name infoPrint. ')' infoPrintCR.
-
-    self become:(self copyEmpty)
-
-    "
-     #(1 2 3 4 5) copy removeAll    
-     #(1 2 3 4 5) removeAll    
-    "
-
-    "Modified: 10.1.1997 / 15:14:55 / cg"
-! !
-
 !ArrayedCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ArrayedCollection.st,v 1.68 2014-12-11 17:07:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ArrayedCollection.st,v 1.69 2014-12-11 17:08:43 cg Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libbasic/ArrayedCollection.st,v 1.69 2014-12-11 17:08:43 cg Exp $'
 ! !