OrderedDictionary (was: Re: [squeak-dev] Re: The Trunk:
Collections-mt.593.mcz)
Bert Freudenberg
bert at freudenbergs.de
Fri Jan 16 16:50:55 UTC 2015
On 16.01.2015, at 17:28, Marcel Taeumel <marcel.taeumel at student.hpi.uni-potsdam.de> wrote:
>
> Okay, the Array >> #do: comes down to Number's:
>
> to: stop do: aBlock
> "Normally compiled in-line, and therefore not overridable.
> Evaluate aBlock for each element of the interval (self to: stop by: 1)."
> | nextValue |
> nextValue := self.
> [nextValue <= stop]
> whileTrue:
> [aBlock value: nextValue.
> nextValue := nextValue + 1]
No, the to:do: is inlined. Look at the bytecodes ...
do: aBlock
1 to: self size do:
[:index | aBlock value: (self at: index)]
> And the LinkedList >> #do: is:
>
> do: aBlock
> | aLink |
> aLink := firstLink.
> [aLink == nil] whileFalse:
> [aBlock value: aLink.
> aLink := aLink nextLink]
>
> So Array iteration has the incrementation of 1 in each iteration. That makes
> the difference? I thought that #to:do: is optimized as it does not appear on
> the stack... :)
The difference is that #at: is much more expensive than #nextLink.
Interestingly, on the interpreter VM the Array version is ever so slightly faster.
- Bert -
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4115 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20150116/4ad4f92b/smime.bin
More information about the Squeak-dev
mailing list
|