OrderedCollection.st
branchjv
changeset 18037 4cf874da38c9
parent 18011 deb0c3355881
parent 14919 b9cc5dc5dc6b
child 18043 03660093fe98
--- a/OrderedCollection.st	Mon Mar 18 22:12:08 2013 +0000
+++ b/OrderedCollection.st	Fri Mar 22 09:18:54 2013 +0000
@@ -55,7 +55,8 @@
       Although insertion and removal of inner elements is possible and supported,
       it may be slow, because remaining elements have to be copied.
       If many elements have to be removed out of the middle of a big OC,
-      it is often faster to create a new OC from scratch.
+      it is often faster to create a new OC from scratch or to use another collection
+      class (SegmentedOrderedCollection) which is specialized for this kind of usage.
 
 
     [beginners bug hint:]
@@ -797,7 +798,7 @@
      the elements under stopIndex.
      Return the receiver.
      Returning the receiver here is a historic leftover - it may change.
-     Please use yourself in a cascade, if you need the receivers value
+     Please use yourself in a cascade, if you need the receiver's value
      when using this method."
 
     |nDeleted "{ Class: SmallInteger }"
@@ -1355,32 +1356,38 @@
 !OrderedCollection methodsFor:'grow & shrink'!
 
 grow:newSize
-    "grow the receiver to newSize"
+    "grow the receiver to newSize. 
+     This only logically changes the receiver's size; 
+     the underlying contentsArray is kept (except if growing to 0 size)"
 
     |oldSize newContents oldLast newLast|
 
     oldSize := lastIndex - firstIndex + 1.
     newSize ~~ oldSize ifTrue:[
-	newLast := firstIndex + newSize - 1.
-	newSize < oldSize ifTrue:[
-	    oldLast := lastIndex.
-	    lastIndex := newLast.
-	    "
-	     nil out rest, to give GC a chance to reclaim things
-	    "
-	    contentsArray from:lastIndex + 1 to:oldLast put:nil. 
-	] ifFalse:[
-	    newLast <= contentsArray size ifTrue:[
-		lastIndex := newLast.
-		^ self
-	    ].
+        newLast := firstIndex + newSize - 1.
+        newSize < oldSize ifTrue:[
+            newSize == 0 ifTrue:[
+                self initContents:10.
+                ^ self.
+            ].
+            oldLast := lastIndex.
+            lastIndex := newLast.
+            "
+             nil out rest, to give GC a chance to reclaim things
+            "
+            contentsArray from:lastIndex + 1 to:oldLast put:nil. 
+        ] ifFalse:[
+            newLast <= contentsArray size ifTrue:[
+                lastIndex := newLast.
+                ^ self
+            ].
 
-	    newContents := Array basicNew:newSize.
-	    newContents replaceFrom:1 to:oldSize with:contentsArray startingAt:firstIndex.
-	    contentsArray := newContents.
-	    firstIndex := 1.
-	    lastIndex := newSize
-	]
+            newContents := Array basicNew:newSize.
+            newContents replaceFrom:1 to:oldSize with:contentsArray startingAt:firstIndex.
+            contentsArray := newContents.
+            firstIndex := 1.
+            lastIndex := newSize
+        ]
     ]
 ! !
 
@@ -1933,6 +1940,6 @@
 !OrderedCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.101 2012-12-21 11:59:35 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.103 2013-03-20 11:47:41 cg Exp $'
 ! !