semantics of #clone?

Yoshiki.Ohshima at acm.org Yoshiki.Ohshima at acm.org
Tue Jun 24 12:44:27 UTC 2003


  Lex,

> I have thought of it as slightly more primitive, too.  A shallow copy of
> an OrderedCollection, for example, might copy slightly more deeply than
> a #clone would (hmm, and that's what it does).

> Right now, Squeak's clone does do as much as nil out the variables --
> it's in fact the same primitive as the default shallowCopy.  This seems
> like a good idea for Squeak, where safety is a higher priority than
> speed.

  Ah, does it?  What I meant by nil-out is to clear the newly created
object *before* copying the actual value.  Since the primitive knows
that all slots of new object will be filled with "safe" values, which
are stored in the original object, the primitive doesn't have to
nil-out the slots.  The current implementation seems carefully avoid
the redundant memory write.

  Of course, the #shallowCopy of SequenceableCollection is implemented
in Squeak.  Which makes it slower than the primitive.

-- Yoshiki



More information about the Squeak-dev mailing list