Discussion:
semantics of #clone?
Joshua 'Schwa' Gargus
2012-01-28 11:26:25 UTC
Permalink
What are the semantics of #clone? Object>>clone has no method
comment. How is it different from the intended meaning of
#shallowCopy?

Thanks,
Joshua
Yoshiki.Ohshima at acm.org ()
2012-01-28 11:26:26 UTC
Permalink
Josh,
Post by Joshua 'Schwa' Gargus
What are the semantics of #clone? Object>>clone has no method
comment. How is it different from the intended meaning of
#shallowCopy?
I guess some other people have better ansser, but for me, #clone is
ensured to be more primitive and faster. Since it doesn't nil-out or
zero-out the newly created object, it is faster for objects like
Bitmap. In the other words, #clone is thin layer on the primitive,
while #shallowCopy has more flexibility to do something different.

# I somehow am feeling that #clone is added later, in 2.x days.

-- Yoshiki
Lex Spoon
2012-01-28 11:26:26 UTC
Permalink
Post by Yoshiki.Ohshima at acm.org ()
Josh,
Post by Joshua 'Schwa' Gargus
What are the semantics of #clone? Object>>clone has no method
comment. How is it different from the intended meaning of
#shallowCopy?
I guess some other people have better ansser, but for me, #clone is
ensured to be more primitive and faster. Since it doesn't nil-out or
zero-out the newly created object, it is faster for objects like
Bitmap. In the other words, #clone is thin layer on the primitive,
while #shallowCopy has more flexibility to do something different.
# I somehow am feeling that #clone is added later, in 2.x days.
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.

Lex
Joshua 'Schwa' Gargus
2012-01-28 11:26:26 UTC
Permalink
Thanks for both of your answers,

Joshua
Post by Lex Spoon
Post by Yoshiki.Ohshima at acm.org ()
Josh,
Post by Joshua 'Schwa' Gargus
What are the semantics of #clone? Object>>clone has no method
comment. How is it different from the intended meaning of
#shallowCopy?
I guess some other people have better ansser, but for me, #clone is
ensured to be more primitive and faster. Since it doesn't nil-out or
zero-out the newly created object, it is faster for objects like
Bitmap. In the other words, #clone is thin layer on the primitive,
while #shallowCopy has more flexibility to do something different.
# I somehow am feeling that #clone is added later, in 2.x days.
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.
Lex
Yoshiki.Ohshima at acm.org ()
2012-01-28 11:26:26 UTC
Permalink
Lex,
Post by Lex Spoon
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
Lex Spoon
2012-01-28 11:26:31 UTC
Permalink
Post by Yoshiki.Ohshima at acm.org ()
Post by Lex Spoon
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.
Oh, yes, you're right -- I posted too quickly. There is no variable
left undefined, so there is no need to nil anything out.


Lex

Loading...