[squeak-dev] Re: Gradient Fills Failures
glenpaling
glenpaling at rogers.com
Wed Mar 2 15:41:58 UTC 2011
nicolas cellier-2 wrote:
>
> 2011/3/1 Nicolas Cellier :
>> Nice catch.
>>
>> I think a simple solution would be to prevent mutation of colorRamp
>> inst. var, and replace mutation with a copy.
>> I don't see any use for these associations to be shared...
>> There are currently two mutators:
>> #firstColor:forMorph:hand: and #lastColor:forMorph:hand:
>>
>> Another solution would be to put a colorRamp deepCopy in the factory
>> like you proposed
>> initPixelRampCache.
>> ^PixelRampCache := LRUCache size: 32 factory:[:key|
>> (GradientFillStyle new colorRamp: key deepCopy)
>> computePixelRampOfSize: 512]
>
> Oops, this was stupid...
> Of course, the copy protection here does not protect anything...
> The protection should lie in pixelRamp
>
> pixelRamp
> "Compute a pixel ramp, and cache it for future accesses"
>
> ^pixelRamp ifNil:[
> "Insure the PixelRampCache is in place"
> PixelRampCache ifNil:[ self class initPixelRampCache ].
> "Ask my cache for an existing instance if one is available"
> pixelRamp := PixelRampCache at: colorRamp deepCopy
> ].
>
Yes that's right. I'll post a fix to the inbox.
nicolas cellier-2 wrote:
>
>>
>> I don't think that protecting the LRUCache is a good idea.
>> #deepCopy may cause infinite loop on object cyclic graphs
>> IMO the programmer shall be in charge of copying.
>>
>> Anyway, the hash is inefficient indeed, most colorRamps share the same
>> keys...
>> {
>> (((GradientFillStyle classPool at: #PixelRampCache) instVarAt:
>> (LRUCache allInstVarNames indexOf: 'values')) collect: [:e | e at: 2]
>> as: Set) size.
>> ((GradientFillStyle classPool at: #PixelRampCache) instVarAt:
>> (LRUCache allInstVarNames indexOf: 'values')) size.
>> }
>> -> #(7 32)
>>
>> I have no immediate solution for this one...
>
Provide LRUCache with a custom hash function.
nicolas cellier-2 wrote:
>
>> Nicolas
>>
>
Glen
--
View this message in context: http://forum.world.st/Gradient-Fills-Failures-tp3330016p3331702.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.
More information about the Squeak-dev
mailing list
|