diff -r ce92d04c41cc -r 652d17daeeb5 OrderedCollection.st --- a/OrderedCollection.st Sat Feb 01 12:15:26 1997 +0100 +++ b/OrderedCollection.st Sat Feb 01 12:37:19 1997 +0100 @@ -511,29 +511,40 @@ if not, return the value from evaluating exceptionBlock. Used equality compare (=) to search for the element." - |index "{ Class:SmallInteger }"| + |index retVal| + + index := contentsArray indexOf:anObject startingAt:firstIndex endingAt:lastIndex. + index ~~ 0 ifTrue:[ + "/ mhmh - should we use removeAtIndex: here ? - index := firstIndex. - [index <= lastIndex] whileTrue:[ - anObject = (contentsArray at:index) ifTrue:[ - contentsArray - replaceFrom:index - to:(contentsArray size - 1) - with:contentsArray - startingAt:(index + 1). + retVal := contentsArray at:index. + + index == firstIndex ifTrue:[ + "/ nil it (helps GC) + contentsArray at:firstIndex put:nil. + firstIndex := firstIndex + 1. + ] ifFalse:[ + index ~~ lastIndex ifTrue:[ + "/ shuffle + + contentsArray + replaceFrom:index + to:(contentsArray size - 1) + with:contentsArray + startingAt:(index + 1). + ]. "/ nil it (helps GC) contentsArray at:lastIndex put:nil. + lastIndex := lastIndex - 1. + ]. - lastIndex := lastIndex - 1. - firstIndex > lastIndex ifTrue:[ - "reset to avoid ever growing" - firstIndex := 1. - lastIndex := 0 - ]. - ^ anObject + firstIndex > lastIndex ifTrue:[ + "reset to avoid ever growing" + firstIndex := 1. + lastIndex := 0 ]. - index := index + 1 + ^ retVal ]. ^ exceptionBlock value @@ -547,7 +558,7 @@ #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection removeIdentical:4 ifAbsent:'oops' " - "Modified: 1.2.1997 / 11:53:12 / cg" + "Modified: 1.2.1997 / 12:29:55 / cg" ! removeAll @@ -606,20 +617,21 @@ |anObject | firstIndex > lastIndex ifTrue:[ - "error if collection is empty" - ^ self emptyCollectionError. + "error if collection is empty" + ^ self emptyCollectionError. ]. + anObject := contentsArray at:firstIndex. "/ nil it out, to allow GC to reclaim it. + contentsArray at:firstIndex put:nil. - contentsArray at:firstIndex put:nil. firstIndex := firstIndex + 1. firstIndex > lastIndex ifTrue:[ - "reset to avoid ever growing" - firstIndex := 1. - lastIndex := 0 + "reset to avoid ever growing" + firstIndex := 1. + lastIndex := 0 ]. ^ anObject @@ -628,6 +640,8 @@ OrderedCollection new removeFirst (SortedCollection withAll:#(5 4 3 2 1)) removeFirst; yourself " + + "Modified: 1.2.1997 / 12:30:50 / cg" ! removeFirst:n @@ -713,40 +727,49 @@ "remove the first element which is identical to anObject; if found, remove and return it; if not, return the value from evaluating exceptionBlock. - Used equality compare (==) to search for the element." + Used identity compare (==) to search for the element." + + |index| - |index "{ Class:SmallInteger }"| + index := contentsArray identityIndexOf:anObject startingAt:firstIndex endingAt:lastIndex. + index ~~ 0 ifTrue:[ + "/ mhmh - should we use removeAtIndex: here ? - index := firstIndex. - [index <= lastIndex] whileTrue:[ - anObject == (contentsArray at:index) ifTrue:[ - contentsArray - replaceFrom:index - to:(contentsArray size - 1) - with:contentsArray - startingAt:(index + 1). + index == firstIndex ifTrue:[ + "/ nil it (helps GC) + contentsArray at:firstIndex put:nil. + firstIndex := firstIndex + 1. + ] ifFalse:[ + index ~~ lastIndex ifTrue:[ + "/ shuffle + + contentsArray + replaceFrom:index + to:(contentsArray size - 1) + with:contentsArray + startingAt:(index + 1). + ]. "/ nil it (helps GC) contentsArray at:lastIndex put:nil. + lastIndex := lastIndex - 1. + ]. - lastIndex := lastIndex - 1. - firstIndex > lastIndex ifTrue:[ - "reset to avoid ever growing" - firstIndex := 1. - lastIndex := 0 - ]. - ^ anObject + firstIndex > lastIndex ifTrue:[ + "reset to avoid ever growing" + firstIndex := 1. + lastIndex := 0 ]. - index := index + 1 + ^ anObject ]. ^ exceptionBlock value " - #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection remove:4 ifAbsent:'oops' + #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection remove:4 ifAbsent:'oops' #(1.0 2.0 3.0 4.0 5.0) asOrderedCollection removeIdentical:4 ifAbsent:'oops' " - "Modified: 1.2.1997 / 11:53:47 / cg" + "Modified: 1.2.1997 / 12:29:47 / cg" ! removeLast @@ -1602,5 +1625,5 @@ !OrderedCollection class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.56 1997-02-01 10:54:01 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.57 1997-02-01 11:37:19 cg Exp $' ! !