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

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>13250</bug_id>
          
          <creation_ts>2011-07-14 15:25:07 +0000</creation_ts>
          <short_desc>In &quot;replace data&quot;, bail out early if the data will be the same</short_desc>
          <delta_ts>2011-07-24 18:04:13 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>DOM</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>13164</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Aryeh Gregor">ayg</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>bzbarsky</cc>
    
    <cc>mike</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>51026</commentid>
    <comment_count>0</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-07-14 15:25:07 +0000</bug_when>
    <thetext>Before the step &quot;Insert data into data after offset code units.&quot;, add something like

  # Substring data with offset offset and count count, and let current data be the result.
  # If current data equals data, terminate these steps.

That way, if there&apos;s no actual change, mutation events won&apos;t fire and ranges won&apos;t be affected.  E.g., if you have a selection in a text node like foo[bar]baz, and you do text.data = text.data, we want the selection to remain foo[bar]baz and not become []foobarbaz.

Among browsers I tested a few months ago, Chrome does this special-casing, and it makes sense.  That way text.data = text.data is a no-op, which is what you&apos;d expect.  Authors are likely to do things like

  function getNewData(data) {
    if (flibberty()) {
      data += &quot;!&quot;;
    }
    if (squizzle()) {
      data = data.replace(/elephant/g, &quot;cantaloupe&quot;);
    }
    return data;
  }
  text.data = getNewData(text.data);

and will naturally expect that nothing will happen if flibberty() and squizzle() are both false.  Of course, if they&apos;re really worried about range mutations they should be passing the actual text node and using appendData/replaceData to make the changes, but we can at least make it easy for them to get it right in as many cases as possible.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51027</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-07-14 15:29:58 +0000</bug_when>
    <thetext>This may or may not make sense.  Actually doing the check to see whether the data is the same is not exactly cheap, and is a definite performance loss when the data is NOT the same...

I can see this going either way, but I think you should look for some implementor feedback here.  There may actually be a reason no one but Chrome does this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51028</commentid>
    <comment_count>2</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-07-14 15:39:54 +0000</bug_when>
    <thetext>Well, it&apos;s certainly simpler not to do it, and more closely matches browsers.  Plus authors can easily emulate the effect if they care, and in almost no cases *will* they care what happens to Ranges.  Plus Anne pointed out that for mutation events, we probably do want to give listeners the chance to react even if the new data is the same.  So I&apos;m withdrawing this request, and will remove the special case from DOM Range, unless someone wants to keep it.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>