[squeak-dev] #clone and #shallowCopy (was: Re: The Trunk: Collections-ul.748.mcz)
Levente Uzonyi
leves at caesar.elte.hu
Sun Apr 23 18:57:54 UTC 2017
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
Levente
P.S.: this was done long ago in Pharo
More information about the Squeak-dev
mailing list
|