[ENH] 33% faster macroBenchmark1 and method prettyprinting.
tim at sumeru.stanford.edu
Wed Oct 10 05:19:23 UTC 2001
I think you'll find that your code
> !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)
... is rather incorrect, too.
'targetCollection' and 'j#'are not used at all. 'self species new' will
create an OrderedCollection of size 10 and make an Array of size 10
that you immediately throw away. Very wasteful.
Something more like 'self species basicNew setContents:' would be
closer. However, note that you would then have to implement extra
versions of #copyFrom:to: for various subclasses of OrderedCollection to
compensate for this; when the current method loops adding each element
to the new collection many things are taken care of by the new
collection. By fiddling around very explicitly you lose that safety net.
I note that SortedCollection already needs some work to reimplement
#copyFrom:to: etc to deal with the sortBlock instvar. And just how can
we implement SortedCollection>reversed? Or #copyReplaceFrom:to:with: ?
Aside of course from 'self shouldNotImplement'....
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
I do not fear computers. I fear the lack of them. - Isaac Asimov
More information about the Squeak-dev