[FIX] Re: DependentsArray size and subscript is out of bounds

mathieu mathk.sue at gmail.com
Sat Jul 22 11:16:00 UTC 2006


Andrew Tween a écrit :
> ..
>> if you try this:
>>
>> | a |
>> a := DependentsArray new.
>> [1 to: 1000 do: [:i | a := a copyWith: Object new]] timeToRun
>>
>> The old code will complete that in less than a second. Your version
>> takes 3 minutes (I think because of hidden size calls on the
>> DependentsArray which are very expensive). This is not a realistic
>> use case, but still ;-)
> 
> Well...the old code fails within a second , at least on my machine ;)
> With a slightly different test...
>     | a |
>     a := DependentsArray new.
>     [1 to: 1000 do: [:i | a := a copyWith: i]] timeToRun.
> I get these timings...
> old code: 5.5 minutes
> my fix: 5.6 minutes
> 
>> I suggest the following:
>>
>> copyWith: newElement
>> "Re-implemented to not copy any niled out dependents."
>> | copy i |
>> copy := self class new: self size + 1.
>> i := 0.
>> self do: [:item | copy at: (i:=i+1) put: item].
>> copy at: (i:=i+1) put: newElement.
>> ^copy

Yes! Well done. SmaCC works fine now thanks

>>
>> This appears to be even more efficient than the original. I'll attach
>> the CS.
> 
> Using the same timing test as above, we have....
> 
> old code: 5.5 minutes
> my fix: 5.6 minutes
> your fix: 0.6 seconds
> 
> Congrats. I think that qualifies for 'speed-up' of the day (or month, or year,
> or decade ?)
> Cheers,
> Andy
> 
> ..
> 
> 




More information about the Squeak-dev mailing list