diff -r 373cc0ac5f71 -r 09ca874a6160 OrderedCollection.st --- a/OrderedCollection.st Sat Nov 09 10:42:57 2019 +0100 +++ b/OrderedCollection.st Sat Nov 09 15:30:46 2019 +0100 @@ -597,26 +597,26 @@ addAll:aCollection beforeIndex:index "insert all elements of the argument, anObject to become located at index. - The collection may be unordered, but then order of the sliced-in elements + The collection may be unordered, but then the order of the sliced-in elements is undefined. Return the receiver." |idx count| aCollection isSequenceable ifTrue:[ - "/ we are lucky - that thing can count & do bulk copies - - count := aCollection size. - idx := self makeRoomAtIndex:(index + firstIndex - 1) for:count. - "/ notice: the above may change firstIndex - contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:1. - ^ self + "/ we are lucky - that thing can count & do bulk copies + + count := aCollection size. + idx := self makeRoomAtIndex:(index + firstIndex - 1) for:count. + "/ notice: the above may change firstIndex + contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:1. + ^ self ]. idx := index. aCollection do:[:element | - self add:element beforeIndex:idx. - idx := idx + 1. + self add:element beforeIndex:idx. + idx := idx + 1. ]. " @@ -669,6 +669,42 @@ "Created: / 30-07-2018 / 11:15:05 / Stefan Vogel" ! +addAllFirst:aCollection + "insert all elements of the argument, aCollection at the beginning + of the receiver. Returns the argument, aCollection." + + self addAll:aCollection beforeIndex:1. + ^ aCollection + + " + |c| + c := #(1 2 3 4) asOrderedCollection. + c addAllFirst:#(10 20 30). + c + " + " + |c| + c := #(1 2 3 4) asOrderedCollection. + c addAllFirst:#(). + c + " + + " + |c| + c := #() asOrderedCollection. + c addAllFirst:#(10 20 30). + c + " + " + |c| + c := #() asOrderedCollection. + c addAllFirst:#(). + c + " + + "Modified: / 12.11.1997 / 17:58:05 / cg" +! + addFirst:anObject "add the argument, anObject to the beginning of the collection. Return the argument, anObject." @@ -1824,7 +1860,6 @@ ! ! - !OrderedCollection methodsFor:'private'! containerClass