OrderedCollection.st
changeset 506 984b32fe635a
parent 407 4656034aa781
child 508 cba92a0c84ac
--- a/OrderedCollection.st	Wed Nov 08 13:16:14 1995 +0100
+++ b/OrderedCollection.st	Wed Nov 08 13:16:58 1995 +0100
@@ -21,7 +21,7 @@
 COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.33 1995-08-24 20:41:22 claus Exp $
+$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.34 1995-11-08 12:16:58 cg Exp $
 '!
 
 !OrderedCollection class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.33 1995-08-24 20:41:22 claus Exp $
+$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.34 1995-11-08 12:16:58 cg Exp $
 "
 !
 
@@ -64,7 +64,7 @@
 new:size
     "create a new OrderedCollection"
 
-    ^ (self basicNew) initContents:size
+    ^ (self basicNew) initContents:(size max:3)
 !
 
 new
@@ -845,33 +845,35 @@
      sz         "{ Class:SmallInteger }"|
 
     oldSize := contentsArray size.
-    oldSize == 0 ifTrue:[ 
+    sz := lastIndex - firstIndex + 1.
+
+    ((oldSize == 0) or:[sz == 0]) ifTrue:[ 
 	contentsArray := Array basicNew:3.
 	firstIndex := 2. lastIndex := 1.
 	^ self
     ].
 
-    sz := lastIndex - firstIndex + 1.
-
     "
      if there is lots of room at the end (> 50%), 
      shift instead of growing. This helps collections
      which get elements removed at the end and added at front.
     "
     oldSize > (sz * 2) ifTrue:[
-	startIndex := oldSize // 4.
-	startIndex == 0 ifTrue:[
-	    startIndex := 1
-	].
-	contentsArray
-	    replaceFrom:startIndex
-	    to:startIndex + sz - 1
-	    with:contentsArray
-	    startingAt:1.
-	contentsArray from:1 to:(startIndex - 1) put:nil.
-	firstIndex := startIndex.
-	lastIndex := startIndex + sz - 1.
-	^ self
+	sz > 1 ifTrue:[
+	    startIndex := oldSize // 4.
+	    startIndex == 0 ifTrue:[
+		startIndex := 1
+	    ].
+	    contentsArray
+		replaceFrom:startIndex
+		to:startIndex + sz - 1
+		with:contentsArray
+		startingAt:1.
+	    contentsArray from:1 to:(startIndex - 1) put:nil.
+	    firstIndex := startIndex.
+	    lastIndex := startIndex + sz - 1.
+	    ^ self
+	]
     ].
     newSize := oldSize * 2.
     newSize == 0 ifTrue:[ newSize := 3].
@@ -884,6 +886,8 @@
     contentsArray := newContents.
     firstIndex := firstIndex + oldSize.
     lastIndex := lastIndex + oldSize
+
+    "Created: 8.11.1995 / 12:47:49 / cg"
 !
 
 makeRoomAtIndex:index