[squeak-dev] Re: Collection>>sum implementation

Paolo Bonzini bonzini at gnu.org
Mon Aug 11 15:18:40 UTC 2008


>> Collection>>reduce: aBlock
>>       ^ self allButFirst inject: self first into: aBlock
>>
> 
> #allButFirst copies the whole collection, where in the current #sum 
> implementation there is no such copy. we should avoid slowing down the 
> method.

That's just an idea, the actual implementation would be

   marker := value := Object new.
   self do: [ :each |
     value := marker == value ifTrue: [ each ]
       ifFalse: [ aBlock value: value value: each ] ]

with an optimized implementation for SequenceableCollection.

Paolo



More information about the Squeak-dev mailing list