[ENH] SequenceableCollection>>forceTo:paddingWith:
Andres Valloud
avalloud at entrypoint.com
Mon Apr 10 16:21:15 UTC 2000
Hi.
This is a much much faster implementation of the above mentioned method.
Andres.
-------------- next part --------------
'From Squeak2.6 of 11 October 1999 [latest update: #1578] on 10 April 2000 at 9:20:11 am'!
!SequenceableCollection methodsFor: 'copying' stamp: 'SqR!!!! 4/10/2000 09:20'!
forceTo: length paddingWith: elem
"Force the length of the collection to length, padding
if necessary with elem. Note that this makes a copy.
Much much faster, SqR!! 4/10/2000 09:19"
| newCollection copyLen padded toPad thisPad |
newCollection _ self species new: length.
copyLen _ self size min: length.
"Copy bulk"
newCollection replaceFrom: 1 to: copyLen
with: self startingAt: 1.
"Fast out"
copyLen = length ifTrue: [^newCollection].
"Fill at the end. Tres cool method"
newCollection at: copyLen + 1 put: elem.
toPad _ length - copyLen. padded _ 1.
[padded = toPad] whileFalse:
[
thisPad _ padded min: toPad - padded.
newCollection
replaceFrom: copyLen + padded + 1 to: copyLen + padded + thisPad
with: newCollection startingAt: copyLen + 1.
padded _ padded + thisPad.
].
^newCollection! !
More information about the Squeak-dev
mailing list
|