faster #removeFromIndex:toIndex.
--- a/OrdColl.st Sat Feb 01 12:37:19 1997 +0100
+++ b/OrdColl.st Sat Feb 01 12:54:38 1997 +0100
@@ -695,32 +695,70 @@
(startIndex < 1
or:[stopIndex > self size]) ifTrue:[
- ^ self notEnoughElementsError
+ ^ self notEnoughElementsError
].
+
+ stopIndex < startIndex ifTrue:[
+ "/ mhmh - what should be done here ?
+ ^ self error:'bad index range'
+ ].
+
nDeleted := stopIndex - startIndex + 1.
- contentsArray
- replaceFrom:(firstIndex + startIndex - 1)
- to:(lastIndex - nDeleted)
- with:contentsArray
- startingAt:(firstIndex + stopIndex).
- "/ nil out rest (helps GC)
- contentsArray
- from:(lastIndex - nDeleted + 1)
- to:lastIndex
- put:nil.
+ "/ can be done faster, when removing the first elements
+ startIndex == firstIndex ifTrue:[
+ "/ nil out (helps GC)
+ contentsArray
+ from:firstIndex
+ to:firstIndex + nDeleted - 1
+ put:nil.
+ firstIndex := firstIndex + nDeleted
+ ] ifFalse:[
+ "/ can be done faster, when removinf the last elements
+ stopIndex == lastIndex ifTrue:[
+ "/ nil out (helps GC)
+ contentsArray
+ from:lastIndex - nDeleted + 1
+ to:lastIndex
+ put:nil.
+ lastIndex := lastIndex - nDeleted
+ ] ifFalse:[
+ "/ must shuffle
+ "/ TODO:
+ "/ for big collections, try to copy the smallest
+ "/ possible number of elements
- lastIndex := lastIndex - nDeleted.
+ contentsArray
+ replaceFrom:(firstIndex + startIndex - 1)
+ to:(lastIndex - nDeleted)
+ with:contentsArray
+ startingAt:(firstIndex + stopIndex).
+
+ "/ nil out rest (helps GC)
+ contentsArray
+ from:(lastIndex - nDeleted + 1)
+ to:lastIndex
+ put:nil.
+
+ lastIndex := lastIndex - nDeleted.
+ ]
+ ].
+
firstIndex > lastIndex ifTrue:[
- "reset to avoid ever growing"
- firstIndex := 1.
- lastIndex := 0
+ "reset to avoid ever growing"
+ firstIndex := 1.
+ lastIndex := 0
]
"
#(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:3 toIndex:6
+ #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:6 toIndex:8
+ #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:1 toIndex:3
+ #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:6 toIndex:9
#(1 2 3 4 5) asOrderedCollection removeFromIndex:3 toIndex:6
"
+
+ "Modified: 1.2.1997 / 12:53:58 / cg"
!
removeIdentical:anObject ifAbsent:exceptionBlock
@@ -1625,5 +1663,5 @@
!OrderedCollection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.57 1997-02-01 11:37:19 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.58 1997-02-01 11:54:38 cg Exp $'
! !
--- a/OrderedCollection.st Sat Feb 01 12:37:19 1997 +0100
+++ b/OrderedCollection.st Sat Feb 01 12:54:38 1997 +0100
@@ -695,32 +695,70 @@
(startIndex < 1
or:[stopIndex > self size]) ifTrue:[
- ^ self notEnoughElementsError
+ ^ self notEnoughElementsError
].
+
+ stopIndex < startIndex ifTrue:[
+ "/ mhmh - what should be done here ?
+ ^ self error:'bad index range'
+ ].
+
nDeleted := stopIndex - startIndex + 1.
- contentsArray
- replaceFrom:(firstIndex + startIndex - 1)
- to:(lastIndex - nDeleted)
- with:contentsArray
- startingAt:(firstIndex + stopIndex).
- "/ nil out rest (helps GC)
- contentsArray
- from:(lastIndex - nDeleted + 1)
- to:lastIndex
- put:nil.
+ "/ can be done faster, when removing the first elements
+ startIndex == firstIndex ifTrue:[
+ "/ nil out (helps GC)
+ contentsArray
+ from:firstIndex
+ to:firstIndex + nDeleted - 1
+ put:nil.
+ firstIndex := firstIndex + nDeleted
+ ] ifFalse:[
+ "/ can be done faster, when removinf the last elements
+ stopIndex == lastIndex ifTrue:[
+ "/ nil out (helps GC)
+ contentsArray
+ from:lastIndex - nDeleted + 1
+ to:lastIndex
+ put:nil.
+ lastIndex := lastIndex - nDeleted
+ ] ifFalse:[
+ "/ must shuffle
+ "/ TODO:
+ "/ for big collections, try to copy the smallest
+ "/ possible number of elements
- lastIndex := lastIndex - nDeleted.
+ contentsArray
+ replaceFrom:(firstIndex + startIndex - 1)
+ to:(lastIndex - nDeleted)
+ with:contentsArray
+ startingAt:(firstIndex + stopIndex).
+
+ "/ nil out rest (helps GC)
+ contentsArray
+ from:(lastIndex - nDeleted + 1)
+ to:lastIndex
+ put:nil.
+
+ lastIndex := lastIndex - nDeleted.
+ ]
+ ].
+
firstIndex > lastIndex ifTrue:[
- "reset to avoid ever growing"
- firstIndex := 1.
- lastIndex := 0
+ "reset to avoid ever growing"
+ firstIndex := 1.
+ lastIndex := 0
]
"
#(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:3 toIndex:6
+ #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:6 toIndex:8
+ #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:1 toIndex:3
+ #(1 2 3 4 5 6 7 8 9) asOrderedCollection removeFromIndex:6 toIndex:9
#(1 2 3 4 5) asOrderedCollection removeFromIndex:3 toIndex:6
"
+
+ "Modified: 1.2.1997 / 12:53:58 / cg"
!
removeIdentical:anObject ifAbsent:exceptionBlock
@@ -1625,5 +1663,5 @@
!OrderedCollection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.57 1997-02-01 11:37:19 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.58 1997-02-01 11:54:38 cg Exp $'
! !