[squeak-dev] Re: Collection's #fold: vs #reduce:

Andreas Raab andreas.raab at gmx.de
Tue Nov 2 19:37:22 UTC 2010

On 11/2/2010 12:25 PM, Eliot Miranda wrote:
> And of course one can consider using thisContext instead of Object new
> or {}, since thisContext has to be instantiated anyway for the closure
> in fold:, and so results in less memory pressure.  This needs careful
> measurement; you have the test bed set up for that; my workspace hacks
> are showing too much variability to distinguish.

I'm sorry but if your application is limited by the performance of 
reduce/fold you're doing it wrong. Can we discuss *clarity* of the 
solution over performance please? If we'd really need a high-performance 
variant, then *nothing* beats a trivial custom implementation in Array 
along the lines of:

Array>>reduce: aBlock

   result := self at: 1.
   2 to: self size do:[:i| result := aBlock value: result value: (self 
at: 1)].

-- "Premature optimization is the root of all evil" --

   - Andreas

More information about the Squeak-dev mailing list