Changeset 181283 in webkit


Ignore:
Timestamp:
Mar 9, 2015 2:10:37 PM (9 years ago)
Author:
benjamin@webkit.org
Message:

CSS JIT: add aliases between :nth-child()/:nth-last-child() and :first-child/:last-child
https://bugs.webkit.org/show_bug.cgi?id=142472

Reviewed by Andreas Kling.

Source/WebCore:

The pseudo class :first-child has weaker tree marking than :nth-child(1).
This patch aliases :nth-child(1) to :first-child in the CSS JIT to take
advantage of that.

The strength of :last-child and :nth-last-child(1) are pretty much identical
but :last-child is a bit simpler so I changed it too. It is also easier
to handle both the same.

Tests: fast/selectors/nth-child-matching-first-on-root.html

fast/selectors/nth-child-matching-first.html
fast/selectors/nth-last-child-matching-first-on-root.html
fast/selectors/nth-last-child-matching-first.html

  • cssjit/SelectorCompiler.cpp:

(WebCore::SelectorCompiler::addNthChildType):
(WebCore::SelectorCompiler::addPseudoClassType):

LayoutTests:

  • fast/selectors/nth-child-matching-first-expected.txt: Added.
  • fast/selectors/nth-child-matching-first-on-root-expected.txt: Added.
  • fast/selectors/nth-child-matching-first-on-root.html: Added.
  • fast/selectors/nth-child-matching-first.html: Added.
  • fast/selectors/nth-last-child-matching-first-expected.txt: Added.
  • fast/selectors/nth-last-child-matching-first-on-root-expected.txt: Added.
  • fast/selectors/nth-last-child-matching-first-on-root.html: Added.
  • fast/selectors/nth-last-child-matching-first.html: Added.
Location:
trunk
Files:
8 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r181278 r181283  
     12015-03-09  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        CSS JIT: add aliases between :nth-child()/:nth-last-child() and :first-child/:last-child
     4        https://bugs.webkit.org/show_bug.cgi?id=142472
     5
     6        Reviewed by Andreas Kling.
     7
     8        * fast/selectors/nth-child-matching-first-expected.txt: Added.
     9        * fast/selectors/nth-child-matching-first-on-root-expected.txt: Added.
     10        * fast/selectors/nth-child-matching-first-on-root.html: Added.
     11        * fast/selectors/nth-child-matching-first.html: Added.
     12        * fast/selectors/nth-last-child-matching-first-expected.txt: Added.
     13        * fast/selectors/nth-last-child-matching-first-on-root-expected.txt: Added.
     14        * fast/selectors/nth-last-child-matching-first-on-root.html: Added.
     15        * fast/selectors/nth-last-child-matching-first.html: Added.
     16
    1172015-03-09  Myles C. Maxfield  <mmaxfield@apple.com>
    218
  • trunk/Source/WebCore/ChangeLog

    r181282 r181283  
     12015-03-09  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        CSS JIT: add aliases between :nth-child()/:nth-last-child() and :first-child/:last-child
     4        https://bugs.webkit.org/show_bug.cgi?id=142472
     5
     6        Reviewed by Andreas Kling.
     7
     8        The pseudo class :first-child has weaker tree marking than :nth-child(1).
     9        This patch aliases :nth-child(1) to :first-child in the CSS JIT to take
     10        advantage of that.
     11
     12        The strength of :last-child and :nth-last-child(1) are pretty much identical
     13        but :last-child is a bit simpler so I changed it too. It is also easier
     14        to handle both the same.
     15
     16        Tests: fast/selectors/nth-child-matching-first-on-root.html
     17               fast/selectors/nth-child-matching-first.html
     18               fast/selectors/nth-last-child-matching-first-on-root.html
     19               fast/selectors/nth-last-child-matching-first.html
     20
     21        * cssjit/SelectorCompiler.cpp:
     22        (WebCore::SelectorCompiler::addNthChildType):
     23        (WebCore::SelectorCompiler::addPseudoClassType):
     24
    1252015-03-09  Benjamin Poulain  <bpoulain@apple.com>
    226
  • trunk/Source/WebCore/cssjit/SelectorCompiler.cpp

    r181197 r181283  
    472472
    473473// Handle the forward :nth-child() and backward :nth-last-child().
    474 static FunctionType addNthChildType(const CSSSelector& selector, SelectorContext selectorContext, FragmentPositionInRootFragments positionInRootFragments, bool visitedMatchEnabled, Vector<std::pair<int, int>, 2>& simpleCases, Vector<NthChildOfSelectorInfo>& filteredCases, unsigned& internalSpecificity)
     474static FunctionType addNthChildType(const CSSSelector& selector, SelectorContext selectorContext, FragmentPositionInRootFragments positionInRootFragments, CSSSelector::PseudoClassType firstMatchAlternative, bool visitedMatchEnabled, Vector<std::pair<int, int>, 2>& simpleCases, Vector<NthChildOfSelectorInfo>& filteredCases, HashSet<unsigned>& pseudoClasses, unsigned& internalSpecificity)
    475475{
    476476    if (!selector.parseNth())
     
    541541        return globalFunctionType;
    542542    }
    543     simpleCases.append(std::pair<int, int>(a, b));
     543
     544    if (b == 1 && a <= 0)
     545        pseudoClasses.add(firstMatchAlternative);
     546    else
     547        simpleCases.append(std::pair<int, int>(a, b));
    544548    if (selectorContext == SelectorContext::QuerySelector)
    545549        return FunctionType::SimpleSelectorChecker;
     
    699703
    700704    case CSSSelector::PseudoClassNthChild:
    701         return addNthChildType(selector, selectorContext, positionInRootFragments, visitedMatchEnabled, fragment.nthChildFilters, fragment.nthChildOfFilters, internalSpecificity);
     705        return addNthChildType(selector, selectorContext, positionInRootFragments, CSSSelector::PseudoClassFirstChild, visitedMatchEnabled, fragment.nthChildFilters, fragment.nthChildOfFilters, fragment.pseudoClasses, internalSpecificity);
    702706
    703707    case CSSSelector::PseudoClassNthLastChild:
    704         return addNthChildType(selector, selectorContext, positionInRootFragments, visitedMatchEnabled, fragment.nthLastChildFilters, fragment.nthLastChildOfFilters, internalSpecificity);
     708        return addNthChildType(selector, selectorContext, positionInRootFragments, CSSSelector::PseudoClassLastChild, visitedMatchEnabled, fragment.nthLastChildFilters, fragment.nthLastChildOfFilters, fragment.pseudoClasses, internalSpecificity);
    705709
    706710    case CSSSelector::PseudoClassNot:
Note: See TracChangeset for help on using the changeset viewer.