OrderedCollection.st
branchjv
changeset 20079 8d884971c2ed
parent 19882 8a3f4071dfec
parent 20026 c4063e226888
child 20348 69376f98c1b4
--- a/OrderedCollection.st	Thu Jun 30 21:11:02 2016 +0100
+++ b/OrderedCollection.st	Thu Jun 30 21:12:35 2016 +0100
@@ -221,7 +221,7 @@
 !OrderedCollection class methodsFor:'initialization'!
 
 initialize
-    MinContentsArraySize := 3. "the minimum size of a non-empty contentsArray"
+    MinContentsArraySize := 4. "the minimum size of a non-empty contentsArray"
 ! !
 
 !OrderedCollection class methodsFor:'instance creation'!
@@ -229,9 +229,6 @@
 new
     "create a new, empty OrderedCollection"
 
-    MinContentsArraySize isNil ifTrue:[
-        self initialize.
-    ].
     ^ self basicNew initContents:0
 
     "
@@ -262,13 +259,7 @@
      See also newWithSize:, which might do what you really want.        
      "
 
-    |sz|
-
-    MinContentsArraySize isNil ifTrue:[
-        self initialize.
-    ].
-    sz := size.
-    ^ self basicNew initContents:sz
+    ^ self basicNew initContents:size
 
     "Modified: 19.3.1996 / 17:53:47 / cg"
 !
@@ -308,13 +299,10 @@
     "create a new, empty OrderedCollection, for which we already know
      that it is very likely to remain empty.
      Use this for collections which may sometimes get elements added, but usually not.
-     This creates an initial contents array of size 0 in contrast to the default new:0,
-     which preserves space for 3 elements."
+     This is now obsolete and the same as new:
+     as the algorithm is now clever enough to deal efficiently with this situation"
 
-    MinContentsArraySize isNil ifTrue:[
-        self initialize.
-    ].
-    ^ self basicNew initContents:0
+    ^ self new:0
 
     "
      self newLikelyToRemainEmpty size
@@ -1359,17 +1347,16 @@
     |newCollection|
 
     newCollection := self copyEmpty:(self size + aCollection size).
-    self do:[:element |
-        newCollection add:element
-    ].
-    aCollection do:[:element |
-        newCollection add:element
-    ].
     ^ newCollection
+        addAll:self;
+        addAll:aCollection;
+        yourself.
 
     "
      #(1 2 3) asOrderedCollection , #(4 5 6) asOrderedCollection
-     #(1 2 3) asSortedCollection , #(99 101 100) asSortedCollection
+     #(1 3 5) asSortedCollection , #(6 4 2) asSortedCollection
+     #(1 3 5) asSortedCollection , #(6 4 2) asOrderedCollection
+     #(1 3 5) asSortedCollection , (#(6 4 2) asSortedCollection:[:a :b| a > b])
     "
 
     "Modified (comment): / 01-04-2012 / 13:17:30 / cg"
@@ -1385,16 +1372,6 @@
     ^ self copyFrom:1 to:self size
 !
 
-copyEmpty
-    "return a copy of the receiver without any elements."
-
-    ^ self copyEmpty:0
-
-    "
-        self new copyEmpty
-    "
-!
-
 postCopy
     "have to copy the contentsArray too"
 
@@ -1722,7 +1699,7 @@
     "setup the receiver-collection to hold size entries"
 
     size == 0 ifTrue:[
-        contentsArray := #().   "save garbage"
+        contentsArray := #().   "save memory by using a shared instance"
     ] ifFalse:[
         contentsArray := Array basicNew:size.
     ].