<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>22479</bug_id>
          
          <creation_ts>2008-11-24 22:50:33 -0800</creation_ts>
          <short_desc>Consider renaming to &apos;deepCopy&apos; the &apos;copy&apos; methods that perform a deep copy</short_desc>
          <delta_ts>2008-11-26 00:33:58 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Darin Fisher (:fishd, Google)">fishd</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>ggaren</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>100162</commentid>
    <comment_count>0</comment_count>
    <who name="Darin Fisher (:fishd, Google)">fishd</who>
    <bug_when>2008-11-24 22:50:33 -0800</bug_when>
    <thetext>Consider renaming to &apos;deepCopy&apos; the &apos;copy&apos; methods that perform a deep copy

This includes at least the copy methods on String, KURL, and SecurityOrigin.

The intent here is to make the method name more self-documenting.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100164</commentid>
    <comment_count>1</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2008-11-24 22:53:28 -0800</bug_when>
    <thetext>Anders mentioned on IRC that &quot;deepCopy&quot; is overkill since &quot;deep&quot; is the default behavior of &quot;copy.&quot; I researched a bit, and I don&apos;t think that&apos;s the case.

&quot;copy&quot; in CSS, the DOM, HistoryItem, DocumentLoader, BindingURI, and StorageMap are not deep. (&quot;copy&quot; in JavaScriptCore is not always deep, either, but maybe that&apos;s not relevant here.)
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100165</commentid>
    <comment_count>2</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2008-11-24 22:54:42 -0800</bug_when>
    <thetext>&quot;copy&quot; *is* deep for: String, StringImpl, SecurityOrigin, KURL.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100207</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-11-25 06:27:28 -0800</bug_when>
    <thetext>I think that StringImpl::deepCopy() would be a misnomer (and a comment in StringImpl.h is already slightly misleading). Also, moving an immutable object across threads doesn&apos;t necessarily involve making a deep copy - e.g. members that are ThreadSafeShared can be shallow-copied.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100270</commentid>
    <comment_count>4</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2008-11-25 13:44:08 -0800</bug_when>
    <thetext>&gt; I think that StringImpl::deepCopy() would be a misnomer (and a comment in
&gt; StringImpl.h is already slightly misleading). 

Why do you think the comment is misleading? Because the reference count doesn&apos;t get copied?

&gt; Also, moving an immutable object
&gt; across threads doesn&apos;t necessarily involve making a deep copy - e.g. members
&gt; that are ThreadSafeShared can be shallow-copied.

If the sole purpose of these functions is to move objects across threads, and they should optimize to copy ThreadSafeShared data in a shallow way, then a name like &quot;threadSafeCopy&quot; would be better. What do you think of that?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100284</commentid>
    <comment_count>5</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-11-25 14:07:15 -0800</bug_when>
    <thetext>(In reply to comment #4)
&gt; Why do you think the comment is misleading? Because the reference count doesn&apos;t
&gt; get copied?

I think I was a bit too quick to criticize the comment.

Maybe I&apos;m just confused trying to understand why copy() is bad - shallow copy is the default one, so a method named copy() should be expected to do something different, shouldn&apos;t it?

&gt; If the sole purpose of these functions is to move objects across threads, and
&gt; they should optimize to copy ThreadSafeShared data in a shallow way, then a
&gt; name like &quot;threadSafeCopy&quot; would be better. What do you think of that?

That seems to be rather wordy, especially for the just added String::substringCopy(). Worse, it doesn&apos;t add much clarity, as it doesn&apos;t describe what is thread safe (it sounds like it is the copy operation itself). And &quot;thread safe&quot; is a very bloated term.

Copying objects across threads is the only reason, but not the only use case - the same function needs to be used when getting/setting values in global objects, such as caches, where names that talk about threads (like &quot;detachFromThread()&quot;) would be confusing, too.

The best I can think of is &quot;copyOut()&quot; - it&apos;s somewhat mysterious, but concise, and close to the meaning that it has in kernel programming. But we won&apos;t have a matching &quot;copyIn()&quot;. Or maybe we could just keep &quot;copy()&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100343</commentid>
    <comment_count>6</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2008-11-25 17:13:21 -0800</bug_when>
    <thetext>&gt; Maybe I&apos;m just confused trying to understand why copy() is bad - shallow copy
&gt; is the default one, so a method named copy() should be expected to do something
&gt; different, shouldn&apos;t it?

There&apos;s disagreement about what the default is. Anders thought that deep copy was the default. Turns out, neither is the default. WebCore is split about 50 / 50, and nothing is the default.

I think it&apos;s important to specify the type of copy in the name because, in a world where there is no default, &quot;copy&quot; is ambiguous. The proof is in the pudding: Each use of copy is annotated by a comment that says &quot;this is a deep copy.&quot; That&apos;s bad programming 101. If &quot;copy&quot; means &quot;deepCopy&quot;, and needs a comment to say so, we should just rename it to &quot;deepCopy,&quot; and get rid of the comment.

I think StringImpl::copy is indeed a &quot;deep&quot; copy. Based on your comments, it seems like it might be invalid to try to optimize copy by not copying ThreadSafeShared data, so I think it is the case that all instances of &quot;copy&quot; that claim to perform a &quot;deep&quot; copy do so, and need to do so.

&gt; The best I can think of is &quot;copyOut()&quot; - it&apos;s somewhat mysterious, but concise,
&gt; and close to the meaning that it has in kernel programming. But we won&apos;t have a
&gt; matching &quot;copyIn()&quot;. Or maybe we could just keep &quot;copy()&quot;.

You&apos;re oversimplifying. If we do nothing, we keep a function named &quot;copy()&quot; where each use is annotated by a comment that says &quot;this is a deep copy.&quot; That seems like the worst of all possible worlds.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100384</commentid>
    <comment_count>7</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-11-26 00:33:58 -0800</bug_when>
    <thetext>(In reply to comment #6)
&gt; Based on your comments, itseems like it might be invalid to 
&gt; try to optimize copy by not copying ThreadSafeShared data

I didn&apos;t mean this, and I think that this would be correct for immutable ThreadSafeShared data - what do you mean?</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>