Changeset 196636 in webkit


Ignore:
Timestamp:
Feb 16, 2016 9:24:01 AM (8 years ago)
Author:
Antti Koivisto
Message:

Factor id mutation style invalidation code into a class
https://bugs.webkit.org/show_bug.cgi?id=154287

Reviewed by Andreas Kling.

Source/WebCore:

Also add a cheap basic optimization that avoids descendant invalidation if they can not be affected.

It would be easy to implement fine grained invalidation like with classes and attribute selectors.
However dynamic id changes are not common enough (nor recommended) to pay the memory cost of
the required data structures.

Test: fast/css/style-invalidation-id-change-descendants.html

  • CMakeLists.txt:
  • WebCore.vcxproj/WebCore.vcxproj:
  • WebCore.xcodeproj/project.pbxproj:
  • css/RuleFeature.cpp:

(WebCore::RuleFeatureSet::recursivelyCollectFeaturesFromSelector):
(WebCore::RuleFeatureSet::add):
(WebCore::RuleFeatureSet::clear):

  • css/RuleFeature.h:
  • dom/Element.cpp:

(WebCore::makeIdForStyleResolution):
(WebCore::Element::attributeChanged):
(WebCore::checkNeedsStyleInvalidationForIdChange): Deleted.

  • style/IdChangeInvalidation.cpp: Added.

(WebCore::Style::IdChangeInvalidation::invalidateStyle):

  • style/IdChangeInvalidation.h: Added.

(WebCore::Style::IdChangeInvalidation::IdChangeInvalidation):
(WebCore::Style::IdChangeInvalidation::~IdChangeInvalidation):

LayoutTests:

  • fast/css/style-invalidation-id-change-descendants-expected.txt: Added.
  • fast/css/style-invalidation-id-change-descendants.html: Added.
Location:
trunk
Files:
4 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r196635 r196636  
     12016-02-16  Antti Koivisto  <antti@apple.com>
     2
     3        Factor id mutation style invalidation code into a class
     4        https://bugs.webkit.org/show_bug.cgi?id=154287
     5
     6        Reviewed by Andreas Kling.
     7
     8        * fast/css/style-invalidation-id-change-descendants-expected.txt: Added.
     9        * fast/css/style-invalidation-id-change-descendants.html: Added.
     10
    1112016-02-16  Ryan Haddad  <ryanhaddad@apple.com>
    212
  • trunk/LayoutTests/fast/css/style-invalidation-attribute-change-descendants-expected.txt

    r196629 r196636  
    1 Test that we invalidate the element subtree minimally on class attribute change
     1Test that we invalidate the element subtree minimally on attribute change
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
  • trunk/LayoutTests/fast/css/style-invalidation-attribute-change-descendants.html

    r196629 r196636  
    7777<script>
    7878
    79 description('Test that we invalidate the element subtree minimally on class attribute change');
     79description('Test that we invalidate the element subtree minimally on attribute change');
    8080
    8181function testStyleChangeType(tag, type)
  • trunk/Source/WebCore/CMakeLists.txt

    r196629 r196636  
    26332633    style/AttributeChangeInvalidation.cpp
    26342634    style/ClassChangeInvalidation.cpp
     2635    style/IdChangeInvalidation.cpp
    26352636    style/InlineTextBoxStyle.cpp
    26362637    style/RenderTreePosition.cpp
  • trunk/Source/WebCore/ChangeLog

    r196633 r196636  
     12016-02-16  Antti Koivisto  <antti@apple.com>
     2
     3        Factor id mutation style invalidation code into a class
     4        https://bugs.webkit.org/show_bug.cgi?id=154287
     5
     6        Reviewed by Andreas Kling.
     7
     8        Also add a cheap basic optimization that avoids descendant invalidation if they can not be affected.
     9
     10        It would be easy to implement fine grained invalidation like with classes and attribute selectors.
     11        However dynamic id changes are not common enough (nor recommended) to pay the memory cost of
     12        the required data structures.
     13
     14        Test: fast/css/style-invalidation-id-change-descendants.html
     15
     16        * CMakeLists.txt:
     17        * WebCore.vcxproj/WebCore.vcxproj:
     18        * WebCore.xcodeproj/project.pbxproj:
     19        * css/RuleFeature.cpp:
     20        (WebCore::RuleFeatureSet::recursivelyCollectFeaturesFromSelector):
     21        (WebCore::RuleFeatureSet::add):
     22        (WebCore::RuleFeatureSet::clear):
     23        * css/RuleFeature.h:
     24        * dom/Element.cpp:
     25        (WebCore::makeIdForStyleResolution):
     26        (WebCore::Element::attributeChanged):
     27        (WebCore::checkNeedsStyleInvalidationForIdChange): Deleted.
     28        * style/IdChangeInvalidation.cpp: Added.
     29        (WebCore::Style::IdChangeInvalidation::invalidateStyle):
     30        * style/IdChangeInvalidation.h: Added.
     31        (WebCore::Style::IdChangeInvalidation::IdChangeInvalidation):
     32        (WebCore::Style::IdChangeInvalidation::~IdChangeInvalidation):
     33
    1342016-02-16  Andreas Kling  <akling@apple.com>
    235
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

    r196629 r196636  
    1929819298    <ClCompile Include="..\style\AttributeChangeInvalidation.cpp" />
    1929919299    <ClCompile Include="..\style\ClassChangeInvalidation.cpp" />
     19300    <ClCompile Include="..\style\IdChangeInvalidation.cpp" />
    1930019301    <ClCompile Include="..\style\InlineTextBoxStyle.cpp" />
    1930119302    <ClCompile Include="..\style\RenderTreePosition.cpp" />
     
    2286922870    <ClInclude Include="..\style\AttributeChangeInvalidation.h" />
    2287022871    <ClInclude Include="..\style\ClassChangeInvalidation.h" />
     22872    <ClInclude Include="..\style\IdChangeInvalidation.h" />
    2287122873    <ClInclude Include="..\style\InlineTextBoxStyle.h" />
    2287222874    <ClInclude Include="..\style\RenderTreePosition.h" />
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r196629 r196636  
    66406640                E4A814D81C70E10500BF85AC /* AttributeChangeInvalidation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4A814D71C70E10500BF85AC /* AttributeChangeInvalidation.cpp */; };
    66416641                E4A814DA1C70E10D00BF85AC /* AttributeChangeInvalidation.h in Headers */ = {isa = PBXBuildFile; fileRef = E4A814D91C70E10D00BF85AC /* AttributeChangeInvalidation.h */; };
     6642                E4A814DE1C7338D100BF85AC /* IdChangeInvalidation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4A814DD1C7338D100BF85AC /* IdChangeInvalidation.cpp */; };
     6643                E4A814E01C7338EB00BF85AC /* IdChangeInvalidation.h in Headers */ = {isa = PBXBuildFile; fileRef = E4A814DF1C7338EB00BF85AC /* IdChangeInvalidation.h */; };
    66426644                E4AE7C1617D1BB950009FB31 /* ElementIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E4AE7C1517D1BB950009FB31 /* ElementIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
    66436645                E4AE7C1A17D232350009FB31 /* ElementAncestorIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E4AE7C1917D232350009FB31 /* ElementAncestorIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1054910551                83D35AEA1C7187ED00F70D5A /* XMLHttpRequestEventTarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLHttpRequestEventTarget.h; sourceTree = "<group>"; };
    1055010552                83D35AEB1C7187ED00F70D5A /* XMLHttpRequestEventTarget.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = XMLHttpRequestEventTarget.idl; sourceTree = "<group>"; };
    10551                 83D35AEF1C718D8400F70D5A /* JSXMLHttpRequestEventTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSXMLHttpRequestEventTarget.cpp; path = JSXMLHttpRequestEventTarget.cpp; sourceTree = "<group>"; };
    10552                 83D35AF01C718D8400F70D5A /* JSXMLHttpRequestEventTarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSXMLHttpRequestEventTarget.h; path = JSXMLHttpRequestEventTarget.h; sourceTree = "<group>"; };
     10553                83D35AEF1C718D8400F70D5A /* JSXMLHttpRequestEventTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSXMLHttpRequestEventTarget.cpp; sourceTree = "<group>"; };
     10554                83D35AF01C718D8400F70D5A /* JSXMLHttpRequestEventTarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSXMLHttpRequestEventTarget.h; sourceTree = "<group>"; };
    1055310555                83E359A01BB1031D002CEB98 /* JSHTMLTimeElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLTimeElement.h; sourceTree = "<group>"; };
    1055410556                83E359A11BB1031D002CEB98 /* JSHTMLTimeElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLTimeElement.cpp; sourceTree = "<group>"; };
     
    1464814650                E4A814D71C70E10500BF85AC /* AttributeChangeInvalidation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AttributeChangeInvalidation.cpp; sourceTree = "<group>"; };
    1464914651                E4A814D91C70E10D00BF85AC /* AttributeChangeInvalidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AttributeChangeInvalidation.h; sourceTree = "<group>"; };
     14652                E4A814DD1C7338D100BF85AC /* IdChangeInvalidation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IdChangeInvalidation.cpp; sourceTree = "<group>"; };
     14653                E4A814DF1C7338EB00BF85AC /* IdChangeInvalidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IdChangeInvalidation.h; sourceTree = "<group>"; };
    1465014654                E4AE7C1517D1BB950009FB31 /* ElementIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementIterator.h; sourceTree = "<group>"; };
    1465114655                E4AE7C1917D232350009FB31 /* ElementAncestorIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementAncestorIterator.h; sourceTree = "<group>"; };
     
    2344223446                                E4A814D51C6DEE8D00BF85AC /* ClassChangeInvalidation.cpp */,
    2344323447                                E4A814D31C6DEC4000BF85AC /* ClassChangeInvalidation.h */,
     23448                                E4A814DD1C7338D100BF85AC /* IdChangeInvalidation.cpp */,
     23449                                E4A814DF1C7338EB00BF85AC /* IdChangeInvalidation.h */,
    2344423450                                1C0106FE192594DF008A4201 /* InlineTextBoxStyle.cpp */,
    2344523451                                1C0106FF192594DF008A4201 /* InlineTextBoxStyle.h */,
     
    2786727873                                E401E0A41C3C0B8300F34D10 /* StyleChange.h in Headers */,
    2786827874                                9DAC7C571AF2CB6400437C44 /* StyleContentAlignmentData.h in Headers */,
     27875                                E4A814E01C7338EB00BF85AC /* IdChangeInvalidation.h in Headers */,
    2786927876                                BC779E171BB227CA00CAA8BF /* StyleCustomPropertyData.h in Headers */,
    2787027877                                BC5EB67F0E81D4A700B25965 /* StyleDashboardRegion.h in Headers */,
     
    3048830495                                B2FA3D5C0AB75A6F000E5AC4 /* JSSVGColor.cpp in Sources */,
    3048930496                                B2FA3D5E0AB75A6F000E5AC4 /* JSSVGComponentTransferFunctionElement.cpp in Sources */,
     30497                                E4A814DE1C7338D100BF85AC /* IdChangeInvalidation.cpp in Sources */,
    3049030498                                B2FA3D600AB75A6F000E5AC4 /* JSSVGCursorElement.cpp in Sources */,
    3049130499                                B2FA3D620AB75A6F000E5AC4 /* JSSVGDefsElement.cpp in Sources */,
  • trunk/Source/WebCore/css/RuleFeature.cpp

    r196629 r196636  
    4040    const CSSSelector* selector = &firstSelector;
    4141    do {
    42         if (selector->match() == CSSSelector::Id)
     42        if (selector->match() == CSSSelector::Id) {
    4343            idsInRules.add(selector->value().impl());
    44         else if (selector->match() == CSSSelector::Class) {
     44            if (matchesAncestor)
     45                idsMatchingAncestorsInRules.add(selector->value().impl());
     46        } else if (selector->match() == CSSSelector::Class) {
    4547            classesInRules.add(selector->value().impl());
    4648            if (matchesAncestor)
     
    119121{
    120122    idsInRules.add(other.idsInRules.begin(), other.idsInRules.end());
     123    idsMatchingAncestorsInRules.add(other.idsMatchingAncestorsInRules.begin(), other.idsMatchingAncestorsInRules.end());
    121124    classesInRules.add(other.classesInRules.begin(), other.classesInRules.end());
    122125    attributeCanonicalLocalNamesInRules.add(other.attributeCanonicalLocalNamesInRules.begin(), other.attributeCanonicalLocalNamesInRules.end());
     
    147150{
    148151    idsInRules.clear();
     152    idsMatchingAncestorsInRules.clear();
    149153    classesInRules.clear();
    150154    attributeCanonicalLocalNamesInRules.clear();
  • trunk/Source/WebCore/css/RuleFeature.h

    r196629 r196636  
    5353
    5454    HashSet<AtomicStringImpl*> idsInRules;
     55    HashSet<AtomicStringImpl*> idsMatchingAncestorsInRules;
    5556    HashSet<AtomicStringImpl*> classesInRules;
    5657    HashSet<AtomicStringImpl*> attributeCanonicalLocalNamesInRules;
  • trunk/Source/WebCore/dom/Element.cpp

    r196629 r196636  
    5858#include "HTMLSelectElement.h"
    5959#include "HTMLTemplateElement.h"
     60#include "IdChangeInvalidation.h"
    6061#include "IdTargetObserverRegistry.h"
    6162#include "KeyboardEvent.h"
     
    12171218}
    12181219
    1219 static bool checkNeedsStyleInvalidationForIdChange(const AtomicString& oldId, const AtomicString& newId, StyleResolver* styleResolver)
    1220 {
    1221     ASSERT(newId != oldId);
    1222     if (!oldId.isEmpty() && styleResolver->hasSelectorForId(oldId))
    1223         return true;
    1224     if (!newId.isEmpty() && styleResolver->hasSelectorForId(newId))
    1225         return true;
    1226     return false;
    1227 }
    1228 
    12291220void Element::attributeChanged(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason)
    12301221{
    12311222    bool valueIsSameAsBefore = oldValue == newValue;
    1232 
    1233     StyleResolver* styleResolver = document().styleResolverIfExists();
    1234     bool testShouldInvalidateStyle = inRenderedDocument() && styleResolver && styleChangeType() < FullStyleChange;
    1235 
    1236     bool shouldInvalidateStyle = false;
    12371223
    12381224    if (!valueIsSameAsBefore) {
     
    12461232            AtomicString newId = makeIdForStyleResolution(newValue, document().inQuirksMode());
    12471233            if (newId != oldId) {
     1234                Style::IdChangeInvalidation styleInvalidation(*this, oldId, newId);
    12481235                elementData()->setIdForStyleResolution(newId);
    1249                 shouldInvalidateStyle = testShouldInvalidateStyle && checkNeedsStyleInvalidationForIdChange(oldId, newId, styleResolver);
    12501236            }
    12511237        } else if (name == classAttr)
     
    12531239        else if (name == HTMLNames::nameAttr)
    12541240            elementData()->setHasNameAttribute(!newValue.isNull());
    1255         else if (name == HTMLNames::pseudoAttr)
    1256             shouldInvalidateStyle |= testShouldInvalidateStyle && isInShadowTree();
     1241        else if (name == HTMLNames::pseudoAttr) {
     1242            if (needsStyleInvalidation() && isInShadowTree())
     1243                setNeedsStyleRecalc(FullStyleChange);
     1244        }
    12571245#if ENABLE(SHADOW_DOM) || ENABLE(DETAILS_ELEMENT)
    12581246        else if (name == HTMLNames::slotAttr) {
     
    12731261
    12741262    invalidateNodeListAndCollectionCachesInAncestors(&name, this);
    1275 
    1276     if (shouldInvalidateStyle)
    1277         setNeedsStyleRecalc();
    12781263
    12791264    if (AXObjectCache* cache = document().existingAXObjectCache())
Note: See TracChangeset for help on using the changeset viewer.