Don't invalidate descendants for nth pseudo classes unless needed
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Mar 2018 16:15:46 +0000 (16:15 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Mar 2018 16:15:46 +0000 (16:15 +0000)
commitbe40accae611d2986f9bb9a82e4aef6f6a779a31
treede97f659883113af3b53e5fb0978a0c441563d50
parent871d804e9803ce0720a9a2d10d6d98444c0c677b
Don't invalidate descendants for nth pseudo classes unless needed
https://bugs.webkit.org/show_bug.cgi?id=183566

Reviewed by Zalan Bujtas.

We currently invalidate the whole subtrees that may match :nth-child and similar. In many common
cases we know that only the direct siblings may be affected.

* css/SelectorChecker.cpp:
(WebCore::localContextForParent):
(WebCore::SelectorChecker::matchRecursively const):

    Track if the context matches the subject element if the selector or its siblings only.

(WebCore::SelectorChecker::checkOne const):

    Use different bits of descendant and child invalidation cases.

* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::fragmentMatchesRightmostOrAdjacentElement):
(WebCore::SelectorCompiler::constructFragmentsInternal):

    Track if the context matches the subject element if the selector or its siblings only.

(WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsNthChild):
(WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsNthChildOf):
(WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsNthLastChild):

    Use different bits of descendant and child invalidation cases.

* dom/Element.cpp:
(WebCore::invalidateForForwardPositionalRules):
(WebCore::invalidateForBackwardPositionalRules):

    Invalidate more precisely based on the new bits.

(WebCore::checkForSiblingStyleChanges):
(WebCore::Element::setDescendantsAffectedByForwardPositionalRules):
(WebCore::Element::setDescendantsAffectedByBackwardPositionalRules):
(WebCore::Element::hasFlagsSetDuringStylingOfChildren const):
(WebCore::Element::rareDataDescendantsAffectedByForwardPositionalRules const):
(WebCore::Element::rareDataDescendantsAffectedByBackwardPositionalRules const):

    New bits.

* dom/Element.h:
(WebCore::Element::descendantsAffectedByForwardPositionalRules const):
(WebCore::Element::descendantsAffectedByBackwardPositionalRules const):
* dom/ElementRareData.h:
(WebCore::ElementRareData::descendantsAffectedByForwardPositionalRules const):
(WebCore::ElementRareData::setDescendantsAffectedByForwardPositionalRules):
(WebCore::ElementRareData::descendantsAffectedByBackwardPositionalRules const):
(WebCore::ElementRareData::setDescendantsAffectedByBackwardPositionalRules):
(WebCore::ElementRareData::ElementRareData):
(WebCore::ElementRareData::resetStyleRelations):
* style/StyleRelations.cpp:
(WebCore::Style::commitRelationsToRenderStyle):
(WebCore::Style::commitRelations):
* style/StyleRelations.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229537 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/css/SelectorChecker.cpp
Source/WebCore/cssjit/SelectorCompiler.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/ElementRareData.h
Source/WebCore/style/StyleRelations.cpp
Source/WebCore/style/StyleRelations.h