[squeak-dev] #clone and #shallowCopy (was: Re: The Trunk: Collections-ul.748.mcz)
Tobias Pape
Das.Linux at gmx.de
Sun Apr 23 19:01:47 UTC 2017
> On 23.04.2017, at 20:57, Levente Uzonyi <leves at caesar.elte.hu> wrote:
>
> On Sun, 23 Apr 2017, Tobias Pape wrote:
>
>>
>>> On 23.04.2017, at 20:20, commits at source.squeak.org wrote:
>>> uses #shallowCopy instead of #clone
>>
>> just curious, why?
>
> Both methods are intended to do the same thing. IIRC #shallowCopy is the cross-dialect method for this purpose, while #clone came with Morphic from Self.
>
> They both use primitive 148 to copy the object.
>
> Object >> #clone used to raise an error when the primitive failed, but that might have just been oversight. Now both methods try to fall back to #basicNew(:) and manually copy the fields, which is what #shallowCopy has always been doing.
>
> However, #clone's fallback code now differs from #shallowCopy's, the latter having the newer timestamp, but the former seems to be simpler, because it relies on #copyFrom:.
> I can't really tell which fallback code is better, so I'll leave that to someone more knowledgeable.
>
> So I suggest we
> - update #shallowCopy if needed to have the best fallback code
> - rewrite senders of #clone from the Trunk to use #shallowCopy
> - deprecate Object >> #clone and make it be a send of #shallowCopy
> - remove other implementors of #clone
'k :)
Thanks
-Tobias
>
> Levente
>
> P.S.: this was done long ago in Pharo
>
More information about the Squeak-dev
mailing list
|