[ENH] 33% faster macroBenchmark1 and method prettyprinting.
Scott A Crosby
crosby at qwes.math.cmu.edu
Wed Oct 10 01:53:01 UTC 2001
On Fri, 5 Oct 2001, Scott A Crosby wrote:
Ok, I found a surprise with this changeset. Apparently, the filelist
browser uses copyReplaceFrom: start to: stop with: replacementCollection
with an Array.
Oops!
Fixed in this new version, I have special cases for array,
orderedcollection, and a catch-all for anything else.
Scott
-------------- next part --------------
'From Squeak3.2alpha of 3 October 2001 [latest update: #4411] on 9 October 2001 at 9:56:15 pm'!
!OrderedCollection methodsFor: 'copying' stamp: 'sac 10/5/2001 12:07'!
copyFrom: startIndex to: endIndex
"Answer a copy of the receiver that contains elements from position
startIndex to endIndex."
| targetCollection j |
endIndex < startIndex
ifTrue: [^ self species new: 0].
targetCollection _ self species new
setContents: (Array new: endIndex + 1 - startIndex).
j _ 0.
^self species new
setContents: (array copyFrom: startIndex + firstIndex - 1 to: endIndex + firstIndex - 1).
! !
!OrderedCollection methodsFor: 'copying' stamp: 'sac 10/9/2001 21:53'!
copyReplaceFrom: start to: stop with: replacementCollection
(replacementCollection isKindOf: OrderedCollection)
ifTrue: [^ self
copyReplaceFrom: start
to: stop
withSortedCollection: replacementCollection].
replacementCollection class == Array
ifTrue: [^ self
copyReplaceFrom: start
to: stop
withArray: replacementCollection].
"Slow backup."
^ self
copyReplaceFrom: start
to: stop
withCollection: replacementCollection! !
!OrderedCollection methodsFor: 'copying' stamp: 'sac 10/9/2001 21:34'!
copyReplaceFrom: start to: stop withArray: replacementCollection
"Answer a copy of the receiver with replacementCollection's elements in
place of the receiver's start'th to stop'th elements. This does not expect
a 1-1 map from replacementCollection to the start to stop elements, so it
will do an insert or append."
"if start is less than 1, ignore stop and assume this is inserting at the
front.
if start greater than self size, ignore stop and assume this is appending.
otherwise, it is replacing part of me and start and stop have to be
within my
bounds."
| delta startIndex stopIndex j arr |
delta _ 0.
startIndex _ start.
stopIndex _ stop.
start < 1
ifTrue: [startIndex _ stopIndex _ 0]
ifFalse: [startIndex > self size
ifTrue: [startIndex _ stopIndex _ self size + 1]
ifFalse: [(stopIndex < (startIndex - 1)
or: [stopIndex > self size])
ifTrue: [self errorOutOfBounds].
delta _ stopIndex - startIndex + 1]].
j _ 0.
arr _ Array new: self size + replacementCollection size - delta.
arr
replaceFrom: j + 1
to: startIndex - 1
with: array
startingAt: firstIndex.
j _ j + startIndex - 1.
arr
replaceFrom: j + 1
to: j + 1 + replacementCollection size - 1
with: replacementCollection.
j _ j + replacementCollection size - 1.
arr
replaceFrom: j + 1
to: j + 1 + self size - (stopIndex + 1)
with: array
startingAt: firstIndex.
^ self species new setContents: arr! !
!OrderedCollection methodsFor: 'copying' stamp: 'sac 10/9/2001 21:35'!
copyReplaceFrom: start to: stop withCollection: replacementCollection
"Answer a copy of the receiver with replacementCollection's elements in
place of the receiver's start'th to stop'th elements. This does not expect
a 1-1 map from replacementCollection to the start to stop elements, so it
will do an insert or append."
"if start is less than 1, ignore stop and assume this is inserting at the
front.
if start greater than self size, ignore stop and assume this is appending.
otherwise, it is replacing part of me and start and stop have to be
within my
bounds."
| newOrderedCollection delta startIndex stopIndex newOrderedCollection2 |
delta _ 0.
startIndex _ start.
stopIndex _ stop.
start < 1
ifTrue: [startIndex _ stopIndex _ 0]
ifFalse: [startIndex > self size
ifTrue: [startIndex _ stopIndex _ self size + 1]
ifFalse: [(stopIndex < (startIndex - 1)
or: [stopIndex > self size])
ifTrue: [self errorOutOfBounds].
delta _ stopIndex - startIndex + 1]].
newOrderedCollection _ self species new: self size + replacementCollection size - delta.
newOrderedCollection2 _ self species new
setContents: (Array new: self size + replacementCollection size - delta).
newOrderedCollection2.
1
to: startIndex - 1
do: [:index | newOrderedCollection
add: (self at: index)].
1
to: replacementCollection size
do: [:index | newOrderedCollection
add: (replacementCollection at: index)].
stopIndex + 1
to: self size
do: [:index | newOrderedCollection
add: (self at: index)].
^ newOrderedCollection! !
!OrderedCollection methodsFor: 'copying' stamp: 'sac 10/9/2001 21:32'!
copyReplaceFrom: start to: stop withSortedCollection: replacementCollection
"Answer a copy of the receiver with replacementCollection's elements in
place of the receiver's start'th to stop'th elements. This does not expect
a 1-1 map from replacementCollection to the start to stop elements, so it
will do an insert or append."
"if start is less than 1, ignore stop and assume this is inserting at the
front.
if start greater than self size, ignore stop and assume this is appending.
otherwise, it is replacing part of me and start and stop have to be
within my
bounds."
| delta startIndex stopIndex j arr |
delta _ 0.
startIndex _ start.
stopIndex _ stop.
start < 1
ifTrue: [startIndex _ stopIndex _ 0]
ifFalse: [startIndex > self size
ifTrue: [startIndex _ stopIndex _ self size + 1]
ifFalse: [(stopIndex < (startIndex - 1)
or: [stopIndex > self size])
ifTrue: [self errorOutOfBounds].
delta _ stopIndex - startIndex + 1]].
j _ 0.
arr _ Array new: self size + replacementCollection size - delta.
arr
replaceFrom: j + 1
to: startIndex - 1
with: array
startingAt: firstIndex.
j _ j + startIndex - 1.
arr
replaceFrom: j + 1
to: j + 1 + replacementCollection size - 1
with: replacementCollection array
startingAt: replacementCollection firstIndex.
j _ j + replacementCollection size - 1.
arr
replaceFrom: j + 1
to: j + 1 + self size - (stopIndex + 1)
with: array
startingAt: firstIndex.
^ self species new setContents: arr! !
!OrderedCollection methodsFor: 'private' stamp: 'sac 10/5/2001 12:28'!
array
^array! !
!OrderedCollection methodsFor: 'private' stamp: 'sac 10/5/2001 12:29'!
firstIndex
^firstIndex! !
OrderedCollection removeSelector: #slowCopyReplaceFrom:to:with:!
More information about the Squeak-dev
mailing list
|