⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 203439 in webkit


Ignore:
Timestamp:
Jul 19, 2016, 6:29:25 PM (10 years ago)
Author:
benjamin@webkit.org
Message:

Use getElementById for attribute matching if the attribute name is html's id
https://bugs.webkit.org/show_bug.cgi?id=159960

Patch by Benjamin Poulain <bpoulain@apple.com> on 2016-07-19
Reviewed by Chris Dumez.

Source/WebCore:

Elliott Sprehn discovered YUI makes heavy uses of querySelector with [id=value]
(https://bugs.chromium.org/p/chromium/issues/detail?id=627242).

If we are not in quirks mode, IdForStyleResolution has the same value
as the Id attribute. We can use the same optimization for both cases.

Tests: fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html

fast/selectors/id-attribute-querySelector-used-as-id-selector.html

  • dom/SelectorQuery.cpp:

(WebCore::canBeUsedForIdFastPath):
(WebCore::findIdMatchingType):
(WebCore::SelectorDataList::SelectorDataList):
(WebCore::selectorForIdLookup):
(WebCore::filterRootById):

LayoutTests:

  • fast/selectors/id-attribute-querySelector-used-as-id-selector-expected.txt: Added.
  • fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks-expected.txt: Added.
  • fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html: Added.
  • fast/selectors/id-attribute-querySelector-used-as-id-selector.html: Added.
Location:
trunk
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r203438 r203439  
     12016-07-19  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Use getElementById for attribute matching if the attribute name is html's id
     4        https://bugs.webkit.org/show_bug.cgi?id=159960
     5
     6        Reviewed by Chris Dumez.
     7
     8        * fast/selectors/id-attribute-querySelector-used-as-id-selector-expected.txt: Added.
     9        * fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks-expected.txt: Added.
     10        * fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html: Added.
     11        * fast/selectors/id-attribute-querySelector-used-as-id-selector.html: Added.
     12
    1132016-07-19  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r203438 r203439  
     12016-07-19  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Use getElementById for attribute matching if the attribute name is html's id
     4        https://bugs.webkit.org/show_bug.cgi?id=159960
     5
     6        Reviewed by Chris Dumez.
     7
     8        Elliott Sprehn discovered YUI makes heavy uses of querySelector with [id=value]
     9        (https://bugs.chromium.org/p/chromium/issues/detail?id=627242).
     10
     11        If we are not in quirks mode, IdForStyleResolution has the same value
     12        as the Id attribute. We can use the same optimization for both cases.
     13
     14        Tests: fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html
     15               fast/selectors/id-attribute-querySelector-used-as-id-selector.html
     16
     17        * dom/SelectorQuery.cpp:
     18        (WebCore::canBeUsedForIdFastPath):
     19        (WebCore::findIdMatchingType):
     20        (WebCore::SelectorDataList::SelectorDataList):
     21        (WebCore::selectorForIdLookup):
     22        (WebCore::filterRootById):
     23
    1242016-07-19  Chris Dumez  <cdumez@apple.com>
    225
  • trunk/Source/WebCore/dom/SelectorQuery.cpp

    r203301 r203439  
    11/*
    2  * Copyright (C) 2011, 2013, 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011, 2013, 2014, 2016 Apple Inc. All rights reserved.
    33 * Copyright (C) 2014 Yusuke Suzuki <utatane.tea@gmail.com>
    44 *
     
    3030#include "CSSParser.h"
    3131#include "ElementDescendantIterator.h"
     32#include "HTMLNames.h"
    3233#include "SelectorChecker.h"
    3334#include "StaticNodeList.h"
     
    5455};
    5556
     57static bool canBeUsedForIdFastPath(const CSSSelector& selector)
     58{
     59    return selector.match() == CSSSelector::Id
     60        || (selector.match() == CSSSelector::Exact && selector.attribute() == HTMLNames::idAttr && !selector.attributeValueMatchingIsCaseInsensitive());
     61}
     62
    5663static IdMatchingType findIdMatchingType(const CSSSelector& firstSelector)
    5764{
    5865    bool inRightmost = true;
    5966    for (const CSSSelector* selector = &firstSelector; selector; selector = selector->tagHistory()) {
    60         if (selector->match() == CSSSelector::Id) {
     67        if (canBeUsedForIdFastPath(*selector)) {
    6168            if (inRightmost)
    6269                return IdMatchingType::Rightmost;
     
    8996                m_matchType = ClassNameMatch;
    9097                break;
    91             case CSSSelector::Id:
    92                 m_matchType = RightMostWithIdMatch;
    93                 break;
    9498            default:
    95                 m_matchType = CompilableSingle;
     99                if (canBeUsedForIdFastPath(selector))
     100                    m_matchType = RightMostWithIdMatch;
     101                else
     102                    m_matchType = CompilableSingle;
    96103                break;
    97104            }
     
    195202
    196203    for (const CSSSelector* selector = &firstSelector; selector; selector = selector->tagHistory()) {
    197         if (selector->match() == CSSSelector::Id)
     204        if (canBeUsedForIdFastPath(*selector))
    198205            return selector;
    199206        if (selector->relation() != CSSSelector::SubSelector)
     
    248255    const CSSSelector* selector = &firstSelector;
    249256    do {
    250         ASSERT(selector->match() != CSSSelector::Id);
     257        ASSERT(!canBeUsedForIdFastPath(*selector));
    251258        if (selector->relation() != CSSSelector::SubSelector)
    252259            break;
     
    256263    bool inAdjacentChain = false;
    257264    for (; selector; selector = selector->tagHistory()) {
    258         if (selector->match() == CSSSelector::Id) {
     265        if (canBeUsedForIdFastPath(*selector)) {
    259266            const AtomicString& idToMatch = selector->value();
    260267            if (ContainerNode* searchRoot = rootNode.treeScope().getElementById(idToMatch)) {
Note: See TracChangeset for help on using the changeset viewer.