Changing id, className, or attribute should invalidate distribution
authorshinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2012 06:50:15 +0000 (06:50 +0000)
committershinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2012 06:50:15 +0000 (06:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=100738

Reviewed by Dimitri Glazkov.

PerformanceTests:

Added test code to modify id/class/attribute.

* DOM/ModifyAttribute.html: Added.
* DOM/resources/dom-perf/modify-attribute.js: Added.
(ModifyAttribute.CreateElementToSetUp):
(ModifyAttribute.ModifyId):
(ModifyAttribute.ModifyClass):
(ModifyAttribute.ModifyTitle):

Source/WebCore:

When id, className, or attribute is changed, we might have to invalidate distribution.
However, we don't want to do useless invalidation. So we consult with the RuleFeatureSet of ElementShadow,
and invalidate distribution only if necessary.

When className is changed, we can share a lot of code between invalidating distribution and invalidating style.
So we made checkNeedsStyleInvalidationForClassChange a template method, and share it.

Also we've measured how this patch makes changing attribute slow. By converting checkNeedsStyleInvalidationForClassChange
to template, actually this improves the performance of changing attribute code. I've measured each code 3 times.

DOM/ModifyAttribute.html
Before this patch:
        median  stdev  min      max    [ms]
  1st   115.62   0.67  114.75   117.00
  2nd   115.08   1.13  113.25   117.58
  3rd   114.75   1.16  113.42   117.83

After this patch:
        median  stdev  min      max    [ms]
  1st   102.55   0.95  101.25   104.50
  2nd   103.10   0.86  102.20   100.95
  3rd   103.30   1.05  102.10   106.65

Tests: fast/dom/shadow/distribution-attribute-modified.html
       fast/dom/shadow/distribution-className-modified.html
       fast/dom/shadow/distribution-id-modified.html
       fast/dom/shadow/reprojection-attribute-modified.html
       fast/dom/shadow/reprojection-className-modified.html
       fast/dom/shadow/reprojection-id-modified.html

* dom/Element.cpp:
(WebCore::Element::attributeChanged):
(WebCore::HasSelectorForClassStyleFunctor::HasSelectorForClassStyleFunctor):
(HasSelectorForClassStyleFunctor):
(WebCore::HasSelectorForClassStyleFunctor::operator()): Returns true if StyleResolver::hasSelectorForClass returns true.
(WebCore):
(WebCore::HasSelectorForClassDistributionFunctor::HasSelectorForClassDistributionFunctor):
(HasSelectorForClassDistributionFunctor):
(WebCore::HasSelectorForClassDistributionFunctor::operator()): Returns true if ElementShadow::hasSelectorForClass returns true.
(WebCore::checkFunctorForClassChange):
(WebCore::checkNeedsStyleInvalidationForClassChange): Extacted the implementation to checkFunctorForClassChange.
(WebCore::checkNeedsDistributionInvalidationForClassChange):
(WebCore::Element::classAttributeChanged):

LayoutTests:

We have test cases that id/class/attribute is changed, and thier reprojection cases.

* fast/dom/shadow/distribution-attribute-modified-expected.html: Added.
* fast/dom/shadow/distribution-attribute-modified.html: Added.
* fast/dom/shadow/distribution-className-modified-expected.html: Added.
* fast/dom/shadow/distribution-className-modified.html: Added.
* fast/dom/shadow/distribution-id-modified-expected.html: Added.
* fast/dom/shadow/distribution-id-modified.html: Added.
* fast/dom/shadow/reprojection-attribute-modified-expected.html: Added.
* fast/dom/shadow/reprojection-attribute-modified.html: Added.
* fast/dom/shadow/reprojection-className-modified-expected.html: Added.
* fast/dom/shadow/reprojection-className-modified.html: Added.
* fast/dom/shadow/reprojection-id-modified-expected.html: Added.
* fast/dom/shadow/reprojection-id-modified.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@134367 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/shadow/distribution-attribute-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/distribution-attribute-modified.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/distribution-className-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/distribution-className-modified.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/distribution-id-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/distribution-id-modified.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-attribute-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-attribute-modified.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-className-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-className-modified.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-id-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-id-modified.html [new file with mode: 0644]
PerformanceTests/ChangeLog
PerformanceTests/DOM/ModifyAttribute.html [new file with mode: 0644]
PerformanceTests/DOM/resources/dom-perf/modify-attribute.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp

index bf34be4..1a2ea1d 100644 (file)
@@ -1,3 +1,25 @@
+2012-11-12  Shinya Kawanaka  <shinyak@chromium.org>
+
+        Changing id, className, or attribute should invalidate distribution
+        https://bugs.webkit.org/show_bug.cgi?id=100738
+
+        Reviewed by Dimitri Glazkov.
+
+        We have test cases that id/class/attribute is changed, and thier reprojection cases.
+
+        * fast/dom/shadow/distribution-attribute-modified-expected.html: Added.
+        * fast/dom/shadow/distribution-attribute-modified.html: Added.
+        * fast/dom/shadow/distribution-className-modified-expected.html: Added.
+        * fast/dom/shadow/distribution-className-modified.html: Added.
+        * fast/dom/shadow/distribution-id-modified-expected.html: Added.
+        * fast/dom/shadow/distribution-id-modified.html: Added.
+        * fast/dom/shadow/reprojection-attribute-modified-expected.html: Added.
+        * fast/dom/shadow/reprojection-attribute-modified.html: Added.
+        * fast/dom/shadow/reprojection-className-modified-expected.html: Added.
+        * fast/dom/shadow/reprojection-className-modified.html: Added.
+        * fast/dom/shadow/reprojection-id-modified-expected.html: Added.
+        * fast/dom/shadow/reprojection-id-modified.html: Added.
+
 2012-11-10  Dirk Schulze  <krit@webkit.org>
 
         BasicShapes 'circle', 'rectangle', 'ellipse' should be animatable with themselves
diff --git a/LayoutTests/fast/dom/shadow/distribution-attribute-modified-expected.html b/LayoutTests/fast/dom/shadow/distribution-attribute-modified-expected.html
new file mode 100644 (file)
index 0000000..4c282c7
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<div id="host">
+    <div>F</div>
+</div>
+
+</html>
diff --git a/LayoutTests/fast/dom/shadow/distribution-attribute-modified.html b/LayoutTests/fast/dom/shadow/distribution-attribute-modified.html
new file mode 100644 (file)
index 0000000..b7c0e62
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<script src="resources/polyfill.js"></script>
+
+<div id="host">
+    <div>A</div>
+    <div>B</div>
+    <div>C</div>
+    <div>D</div>
+    <div>E</div>
+    <div id="F">F</div>
+</div>
+
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+var shadowRoot = new WebKitShadowRoot(host);
+shadowRoot.innerHTML = '<content select="div[title]"></content>';
+
+setTimeout(function() {
+    F.title = 'something';
+    if (window.testRunner)
+        testRunner.notifyDone();
+}, 0);
+</script>
+</html>
diff --git a/LayoutTests/fast/dom/shadow/distribution-className-modified-expected.html b/LayoutTests/fast/dom/shadow/distribution-className-modified-expected.html
new file mode 100644 (file)
index 0000000..d9a695c
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<div id="host">
+    <div>A</div>
+    <div>D</div>
+    <div>F</div>
+</div>
+
+</html>
diff --git a/LayoutTests/fast/dom/shadow/distribution-className-modified.html b/LayoutTests/fast/dom/shadow/distribution-className-modified.html
new file mode 100644 (file)
index 0000000..d548e0d
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<script src="resources/polyfill.js"></script>
+
+<div id="host">
+    <div class="selected">A</div>
+    <div>B</div>
+    <div>C</div>
+    <div class="selected">D</div>
+    <div>E</div>
+    <div id="F">F</div>
+</div>
+
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+var shadowRoot = new WebKitShadowRoot(host);
+shadowRoot.innerHTML = '<content select=".selected"></content>';
+
+setTimeout(function() {
+    F.className = 'selected';
+    if (window.testRunner)
+        testRunner.notifyDone();
+}, 0);
+</script>
+</html>
diff --git a/LayoutTests/fast/dom/shadow/distribution-id-modified-expected.html b/LayoutTests/fast/dom/shadow/distribution-id-modified-expected.html
new file mode 100644 (file)
index 0000000..4c282c7
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<div id="host">
+    <div>F</div>
+</div>
+
+</html>
diff --git a/LayoutTests/fast/dom/shadow/distribution-id-modified.html b/LayoutTests/fast/dom/shadow/distribution-id-modified.html
new file mode 100644 (file)
index 0000000..4e35ce7
--- /dev/null
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<script src="resources/polyfill.js"></script>
+
+<div id="host">
+    <div id="selected">A</div>
+    <div>B</div>
+    <div>C</div>
+    <div>D</div>
+    <div>E</div>
+    <div id="F">F</div>
+</div>
+
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+var shadowRoot = new WebKitShadowRoot(host);
+shadowRoot.innerHTML = '<content select="#selected"></content>';
+
+setTimeout(function() {
+    A = selected;
+    F.id = 'selected';    
+    A.id = '';
+    if (window.testRunner)
+        testRunner.notifyDone();
+}, 0);
+</script>
+</html>
diff --git a/LayoutTests/fast/dom/shadow/reprojection-attribute-modified-expected.html b/LayoutTests/fast/dom/shadow/reprojection-attribute-modified-expected.html
new file mode 100644 (file)
index 0000000..2e5a421
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<div id="host"><div>
+    <div>F</div>
+</div></div>
+
+</html>
diff --git a/LayoutTests/fast/dom/shadow/reprojection-attribute-modified.html b/LayoutTests/fast/dom/shadow/reprojection-attribute-modified.html
new file mode 100644 (file)
index 0000000..335165b
--- /dev/null
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<script src="resources/polyfill.js"></script>
+
+<div id="host1">
+    <div>A</div>
+    <div>B</div>
+    <div>C</div>
+    <div>D</div>
+    <div>E</div>
+    <div id="F">F</div>
+</div>
+
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+var shadowRoot1 = new WebKitShadowRoot(host1);
+shadowRoot1.innerHTML = '<div id="host2"><shadow></shadow></div>';
+
+var host2 = shadowRoot1.getElementById('host2');
+var shadowRoot2 = new WebKitShadowRoot(host2);
+shadowRoot2.innerHTML = '<content select="div[title=selected]"></content>';
+
+setTimeout(function() {
+    F.title = 'selected';
+    if (window.testRunner)
+        testRunner.notifyDone();
+}, 0);
+</script>
+</html>
diff --git a/LayoutTests/fast/dom/shadow/reprojection-className-modified-expected.html b/LayoutTests/fast/dom/shadow/reprojection-className-modified-expected.html
new file mode 100644 (file)
index 0000000..0ee8a60
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<div id="host"><div>
+    <div>A</div>
+    <div>D</div>
+    <div>F</div>
+</div></div>
+
+</html>
diff --git a/LayoutTests/fast/dom/shadow/reprojection-className-modified.html b/LayoutTests/fast/dom/shadow/reprojection-className-modified.html
new file mode 100644 (file)
index 0000000..973da66
--- /dev/null
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<script src="resources/polyfill.js"></script>
+
+<div id="host1">
+    <div class="selected">A</div>
+    <div>B</div>
+    <div>C</div>
+    <div class="selected">D</div>
+    <div>E</div>
+    <div id="F">F</div>
+</div>
+
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+var shadowRoot1 = new WebKitShadowRoot(host1);
+shadowRoot1.innerHTML = '<div id="host2"><shadow></shadow></div>';
+
+var host2 = shadowRoot1.getElementById('host2');
+var shadowRoot2 = new WebKitShadowRoot(host2);
+shadowRoot2.innerHTML = '<content select=".selected"></content>';
+
+setTimeout(function() {
+    F.className = 'selected';
+    if (window.testRunner)
+        testRunner.notifyDone();
+}, 0);
+</script>
+</html>
diff --git a/LayoutTests/fast/dom/shadow/reprojection-id-modified-expected.html b/LayoutTests/fast/dom/shadow/reprojection-id-modified-expected.html
new file mode 100644 (file)
index 0000000..2e5a421
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<div id="host"><div>
+    <div>F</div>
+</div></div>
+
+</html>
diff --git a/LayoutTests/fast/dom/shadow/reprojection-id-modified.html b/LayoutTests/fast/dom/shadow/reprojection-id-modified.html
new file mode 100644 (file)
index 0000000..4000b84
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+
+<html>
+<body>
+
+<script src="resources/polyfill.js"></script>
+
+<div id="host1">
+    <div id="selected">A</div>
+    <div>B</div>
+    <div>C</div>
+    <div>D</div>
+    <div>E</div>
+    <div id="F">F</div>
+</div>
+
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+var shadowRoot1 = new WebKitShadowRoot(host1);
+shadowRoot1.innerHTML = '<div id="host2"><shadow></shadow></div>';
+
+var host2 = shadowRoot1.getElementById('host2');
+var shadowRoot2 = new WebKitShadowRoot(host2);
+shadowRoot2.innerHTML = '<content select="#selected"></content>';
+
+setTimeout(function() {
+    A = selected;
+    A.id = '';
+    F.id = 'selected';
+    if (window.testRunner)
+        testRunner.notifyDone();
+}, 0);
+</script>
+</html>
index 66ad1ba..7be7211 100644 (file)
@@ -1,3 +1,19 @@
+2012-11-12  Shinya Kawanaka  <shinyak@chromium.org>
+
+        Changing id, className, or attribute should invalidate distribution
+        https://bugs.webkit.org/show_bug.cgi?id=100738
+
+        Reviewed by Dimitri Glazkov.
+
+        Added test code to modify id/class/attribute.
+
+        * DOM/ModifyAttribute.html: Added.
+        * DOM/resources/dom-perf/modify-attribute.js: Added.
+        (ModifyAttribute.CreateElementToSetUp):
+        (ModifyAttribute.ModifyId):
+        (ModifyAttribute.ModifyClass):
+        (ModifyAttribute.ModifyTitle):
+
 2012-11-06  Adam Barth  <abarth@webkit.org>
 
         DOMImplementation should use ScriptWrappable
diff --git a/PerformanceTests/DOM/ModifyAttribute.html b/PerformanceTests/DOM/ModifyAttribute.html
new file mode 100644 (file)
index 0000000..d1e259c
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div id="container"><span id="benchmark_content"></span></div>
+<script type="text/javascript" src="../resources/runner.js"></script>
+<script type="text/javascript" src="resources/dom-perf.js"></script>
+<script type="text/javascript" src="resources/dom-perf/modify-attribute.js"></script>
+<script>runBenchmarkSuite(ModifyAttributeTest);</script>
+</body>
+</html>
diff --git a/PerformanceTests/DOM/resources/dom-perf/modify-attribute.js b/PerformanceTests/DOM/resources/dom-perf/modify-attribute.js
new file mode 100644 (file)
index 0000000..3b6e419
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// ModifyAttribute - measure attribute modification performance
+
+var ModifyAttribute = {};
+var nLoops = 100000;
+
+ModifyAttribute.CreateElementToSetUp = function() {
+    return document.createElement('div');
+}
+
+ModifyAttribute.ModifyId = function(element) {
+    var nLoops = window.nLoops;
+    var idValue1 = 'id1';
+    var idValue2 = 'id2';
+
+    for (var i = 0; i < nLoops; ++i) {
+        element.id = idValue1;
+        element.id = idValue2;                        
+    }
+}
+
+ModifyAttribute.ModifyClass = function(element) {
+    var nLoops = window.nLoops;
+    var className1 = 'class1';
+    var className2 = 'class2';
+
+    for (var i = 0; i < nLoops; ++i) {
+        element.className = className1;
+        element.className = className2;
+    }
+}
+
+ModifyAttribute.ModifyTitle = function(element) {
+    var nLoops = window.nLoops;
+    var title1 = 'title1';
+    var title2 = 'title2';
+
+    for (var i = 0; i < nLoops; ++i) {
+        element.title = title1;
+        element.title = title2;
+    }
+}
+
+var ModifyAttributeTest = new BenchmarkSuite('ModifyAttribute', [
+    new Benchmark("Modify id", ModifyAttribute.ModifyId, ModifyAttribute.CreateElementToSetUp),
+    new Benchmark("Modify class", ModifyAttribute.ModifyClass, ModifyAttribute.CreateElementToSetUp),
+    new Benchmark("Modify title", ModifyAttribute.ModifyTitle, ModifyAttribute.CreateElementToSetUp)
+]);
index 2133696..4bd9c36 100644 (file)
@@ -1,3 +1,54 @@
+2012-11-12  Shinya Kawanaka  <shinyak@chromium.org>
+
+        Changing id, className, or attribute should invalidate distribution
+        https://bugs.webkit.org/show_bug.cgi?id=100738
+
+        Reviewed by Dimitri Glazkov.
+
+        When id, className, or attribute is changed, we might have to invalidate distribution.
+        However, we don't want to do useless invalidation. So we consult with the RuleFeatureSet of ElementShadow,
+        and invalidate distribution only if necessary.
+
+        When className is changed, we can share a lot of code between invalidating distribution and invalidating style.
+        So we made checkNeedsStyleInvalidationForClassChange a template method, and share it.
+
+        Also we've measured how this patch makes changing attribute slow. By converting checkNeedsStyleInvalidationForClassChange
+        to template, actually this improves the performance of changing attribute code. I've measured each code 3 times.
+
+        DOM/ModifyAttribute.html
+        Before this patch:
+                median  stdev  min      max    [ms]
+          1st   115.62   0.67  114.75   117.00
+          2nd   115.08   1.13  113.25   117.58
+          3rd   114.75   1.16  113.42   117.83
+
+        After this patch:
+                median  stdev  min      max    [ms]
+          1st   102.55   0.95  101.25   104.50
+          2nd   103.10   0.86  102.20   100.95
+          3rd   103.30   1.05  102.10   106.65
+
+        Tests: fast/dom/shadow/distribution-attribute-modified.html
+               fast/dom/shadow/distribution-className-modified.html
+               fast/dom/shadow/distribution-id-modified.html
+               fast/dom/shadow/reprojection-attribute-modified.html
+               fast/dom/shadow/reprojection-className-modified.html
+               fast/dom/shadow/reprojection-id-modified.html
+
+        * dom/Element.cpp:
+        (WebCore::Element::attributeChanged):
+        (WebCore::HasSelectorForClassStyleFunctor::HasSelectorForClassStyleFunctor):
+        (HasSelectorForClassStyleFunctor):
+        (WebCore::HasSelectorForClassStyleFunctor::operator()): Returns true if StyleResolver::hasSelectorForClass returns true.
+        (WebCore):
+        (WebCore::HasSelectorForClassDistributionFunctor::HasSelectorForClassDistributionFunctor):
+        (HasSelectorForClassDistributionFunctor):
+        (WebCore::HasSelectorForClassDistributionFunctor::operator()): Returns true if ElementShadow::hasSelectorForClass returns true.
+        (WebCore::checkFunctorForClassChange):
+        (WebCore::checkNeedsStyleInvalidationForClassChange): Extacted the implementation to checkFunctorForClassChange.
+        (WebCore::checkNeedsDistributionInvalidationForClassChange):
+        (WebCore::Element::classAttributeChanged):
+
 2012-11-12  Joe Mason  <jmason@rim.com>
 
         [BlackBerry] NetworkJob should not check if data is received with HEAD
index 3b141ec..a6cb7cf 100644 (file)
@@ -53,6 +53,7 @@
 #include "HTMLOptionsCollection.h"
 #include "HTMLParserIdioms.h"
 #include "HTMLTableRowsCollection.h"
+#include "InsertionPoint.h"
 #include "InspectorInstrumentation.h"
 #include "MutationObserverInterestGroup.h"
 #include "MutationRecord.h"
@@ -763,8 +764,13 @@ void Element::attributeChanged(const QualifiedName& name, const AtomicString& ne
     document()->incDOMTreeVersion();
 
     StyleResolver* styleResolver = document()->styleResolverIfExists();
+    ElementShadow* elementShadow = shadowOfParentForDistribution(this);
+    if (elementShadow)
+        elementShadow->ensureSelectFeatureSetCollected();
+
     bool testShouldInvalidateStyle = attached() && styleResolver && styleChangeType() < FullStyleChange;
     bool shouldInvalidateStyle = false;
+    bool shouldInvalidateDistribution = false;
 
     if (isIdAttributeName(name)) {
         AtomicString oldId = attributeData()->idForStyleResolution();
@@ -772,6 +778,8 @@ void Element::attributeChanged(const QualifiedName& name, const AtomicString& ne
         if (newId != oldId) {
             attributeData()->setIdForStyleResolution(newId);
             shouldInvalidateStyle = testShouldInvalidateStyle && checkNeedsStyleInvalidationForIdChange(oldId, newId, styleResolver);
+            shouldInvalidateDistribution |= elementShadow && !oldId.isEmpty() && elementShadow->selectRuleFeatureSet().hasSelectorForId(oldId);
+            shouldInvalidateDistribution |= elementShadow && !newId.isEmpty() && elementShadow->selectRuleFeatureSet().hasSelectorForId(newId);  
         }
     } else if (name == HTMLNames::nameAttr)
         setHasName(!newValue.isNull());
@@ -779,12 +787,15 @@ void Element::attributeChanged(const QualifiedName& name, const AtomicString& ne
         shouldInvalidateStyle |= testShouldInvalidateStyle && isInShadowTree();
 
     shouldInvalidateStyle |= testShouldInvalidateStyle && styleResolver->hasSelectorForAttribute(name.localName());
+    shouldInvalidateDistribution |= elementShadow && elementShadow->selectRuleFeatureSet().hasSelectorForAttribute(name.localName());
 
     invalidateNodeListCachesInAncestors(&name, this);
 
     if (shouldInvalidateStyle)
         setNeedsStyleRecalc();
-
+    if (shouldInvalidateDistribution)
+        elementShadow->invalidateDistribution();
+        
     if (AXObjectCache::accessibilityEnabled())
         document()->axObjectCache()->handleAttributeChanged(name, this);
 }
@@ -822,21 +833,49 @@ static inline bool classStringHasClassName(const AtomicString& newClassString)
     return classStringHasClassName(newClassString.characters16(), length);
 }
 
-static bool checkNeedsStyleInvalidationForClassChange(const SpaceSplitString& changedClasses, StyleResolver* styleResolver)
+struct HasSelectorForClassStyleFunctor {
+    explicit HasSelectorForClassStyleFunctor(StyleResolver* resolver)
+        : styleResolver(resolver)
+    { }
+
+    bool operator()(const AtomicString& className) const
+    {
+        return styleResolver->hasSelectorForClass(className);
+    }
+
+    StyleResolver* styleResolver;
+};
+
+struct HasSelectorForClassDistributionFunctor {
+    explicit HasSelectorForClassDistributionFunctor(ElementShadow* elementShadow)
+        : elementShadow(elementShadow)
+    { }
+
+    bool operator()(const AtomicString& className) const
+    {
+        return elementShadow->selectRuleFeatureSet().hasSelectorForClass(className);
+    }
+
+    ElementShadow* elementShadow;
+};
+
+template<typename Functor>
+static bool checkFunctorForClassChange(const SpaceSplitString& changedClasses, Functor functor)
 {
     unsigned changedSize = changedClasses.size();
     for (unsigned i = 0; i < changedSize; ++i) {
-        if (styleResolver->hasSelectorForClass(changedClasses[i]))
+        if (functor(changedClasses[i]))
             return true;
     }
     return false;
 }
 
-static bool checkNeedsStyleInvalidationForClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses, StyleResolver* styleResolver)
+template<typename Functor>
+static bool checkFunctorForClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses, Functor functor)
 {
     unsigned oldSize = oldClasses.size();
     if (!oldSize)
-        return checkNeedsStyleInvalidationForClassChange(newClasses, styleResolver);
+        return checkFunctorForClassChange(newClasses, functor);
     BitVector remainingClassBits;
     remainingClassBits.ensureSize(oldSize);
     // Class vectors tend to be very short. This is faster than using a hash table.
@@ -848,25 +887,50 @@ static bool checkNeedsStyleInvalidationForClassChange(const SpaceSplitString& ol
                 continue;
             }
         }
-        if (styleResolver->hasSelectorForClass(newClasses[i]))
+        if (functor(newClasses[i]))
             return true;
     }
     for (unsigned i = 0; i < oldSize; ++i) {
         // If the bit is not set the the corresponding class has been removed.
         if (remainingClassBits.quickGet(i))
             continue;
-        if (styleResolver->hasSelectorForClass(oldClasses[i]))
+        if (functor(oldClasses[i]))
             return true;
     }
     return false;
 }
 
+static inline bool checkNeedsStyleInvalidationForClassChange(const SpaceSplitString& changedClasses, StyleResolver* styleResolver)
+{
+    return checkFunctorForClassChange(changedClasses, HasSelectorForClassStyleFunctor(styleResolver));
+}
+
+static inline bool checkNeedsStyleInvalidationForClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses, StyleResolver* styleResolver)
+{
+    return checkFunctorForClassChange(oldClasses, newClasses, HasSelectorForClassStyleFunctor(styleResolver));
+}
+
+static inline bool checkNeedsDistributionInvalidationForClassChange(const SpaceSplitString& changedClasses, ElementShadow* elementShadow)
+{
+    return checkFunctorForClassChange(changedClasses, HasSelectorForClassDistributionFunctor(elementShadow));
+}
+
+static inline bool checkNeedsDistributionInvalidationForClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses, ElementShadow* elementShadow)
+{
+    return checkFunctorForClassChange(oldClasses, newClasses, HasSelectorForClassDistributionFunctor(elementShadow));
+}
+
 void Element::classAttributeChanged(const AtomicString& newClassString)
 {
     StyleResolver* styleResolver = document()->styleResolverIfExists();
     bool testShouldInvalidateStyle = attached() && styleResolver && styleChangeType() < FullStyleChange;
     bool shouldInvalidateStyle = false;
 
+    ElementShadow* elementShadow = shadowOfParentForDistribution(this);
+    if (elementShadow)
+        elementShadow->ensureSelectFeatureSetCollected();
+    bool shouldInvalidateDistribution = false;
+
     if (classStringHasClassName(newClassString)) {
         const ElementAttributeData* attributeData = ensureAttributeData();
         const bool shouldFoldCase = document()->inQuirksMode();
@@ -876,10 +940,11 @@ void Element::classAttributeChanged(const AtomicString& newClassString)
 
         const SpaceSplitString& newClasses = attributeData->classNames();
         shouldInvalidateStyle = testShouldInvalidateStyle && checkNeedsStyleInvalidationForClassChange(oldClasses, newClasses, styleResolver);
+        shouldInvalidateDistribution = elementShadow && checkNeedsDistributionInvalidationForClassChange(oldClasses, newClasses, elementShadow);
     } else if (const ElementAttributeData* attributeData = this->attributeData()) {
         const SpaceSplitString& oldClasses = attributeData->classNames();
         shouldInvalidateStyle = testShouldInvalidateStyle && checkNeedsStyleInvalidationForClassChange(oldClasses, styleResolver);
-
+        shouldInvalidateDistribution = elementShadow && checkNeedsDistributionInvalidationForClassChange(oldClasses, elementShadow);
         attributeData->clearClass();
     }
 
@@ -888,6 +953,8 @@ void Element::classAttributeChanged(const AtomicString& newClassString)
 
     if (shouldInvalidateStyle)
         setNeedsStyleRecalc();
+    if (shouldInvalidateDistribution)
+        elementShadow->invalidateDistribution();
 }
 
 // Returns true is the given attribute is an event handler.