SortedCollection.st
branchjv
changeset 20079 8d884971c2ed
parent 19137 199b5e15b1da
parent 20007 fadbdacd6e66
child 20727 fb8c5591428b
equal deleted inserted replaced
20078:a680abc90e84 20079:8d884971c2ed
   387 
   387 
   388 addAll:aCollection
   388 addAll:aCollection
   389     "add all elements of the argument, aCollection to the receiver.
   389     "add all elements of the argument, aCollection to the receiver.
   390      Returns the argument, aCollection (sigh)."
   390      Returns the argument, aCollection (sigh)."
   391 
   391 
   392     |addedCollection mySize numAdded|
   392     |addedCollection|
   393 
       
   394     numAdded := aCollection size.
       
   395     mySize := self size.
       
   396 
   393 
   397     (aCollection isSortedCollection
   394     (aCollection isSortedCollection
   398      and:[aCollection sortBlock == sortBlock]) ifTrue:[
   395      and:[aCollection sortBlock == sortBlock]) ifTrue:[
   399         addedCollection := aCollection.
   396         addedCollection := aCollection.
   400     ] ifFalse:[
   397     ] ifFalse:[
   401         addedCollection := Array withAll:aCollection.
   398         addedCollection := Array withAll:aCollection.
   402         addedCollection stableSort:sortBlock.
   399         addedCollection stableSort:sortBlock.
   403 
   400 
   404         mySize == 0 ifTrue:[
   401         self size == 0 ifTrue:[
   405             "/ special case: I am empty - add them en-bloque.
   402             "/ special case: I am empty - add them en-bloque.
   406             contentsArray := addedCollection.
   403             contentsArray := addedCollection.
   407             firstIndex := 1.
   404             firstIndex := 1.
   408             lastIndex := numAdded.
   405             lastIndex := aCollection size.
   409             ^ aCollection
   406             ^ aCollection
   410         ].
   407         ].
   411     ].
   408     ].
   412 
   409 
   413     "/
   410     "/