Changeset 94089 in webkit


Ignore:
Timestamp:
Aug 30, 2011 10:43:24 AM (13 years ago)
Author:
Antti Koivisto
Message:

querySelector/querySelectorAll should use selector checker fast path
https://bugs.webkit.org/show_bug.cgi?id=67161

Reviewed by Sam Weinig.

Descendant and child selectors can be matches substantially faster using
SelectorChecker::fastCheckSelector() path. Currently it is used for style matching only.

Add SelectorQuery class that can do both querySelector and querySelectorAll efficiently using
fast path. Use inlined loop for DOM traversal.

The patch is ~25% speedup in the overall native score of http://www.webkit.org/perf/slickspeed/.
Some individual subtests (using child or descendant selectors) execute twice as fast.

  • CMakeLists.txt:
  • GNUmakefile.list.am:
  • WebCore.gypi:
  • WebCore.pro:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSStyleSelector.cpp:

(WebCore::CSSStyleSelector::SelectorChecker::checkSelector):
(WebCore::CSSStyleSelector::SelectorChecker::isFastCheckableSelector):
(WebCore::RuleData::RuleData):

  • css/CSSStyleSelector.h:


Make fast path checking available outside CSSStyleSelector.


  • dom/DOMAllInOne.cpp:
  • dom/Node.cpp:

(WebCore::Node::querySelector):
(WebCore::Node::querySelectorAll):

Switch to SelectorQuery.


  • dom/SelectorNodeList.cpp: Removed.
  • dom/SelectorNodeList.h: Removed.


SelectorQuery makes these obsolete.

  • dom/SelectorQuery.cpp: Added.

(WebCore::SelectorQuery::SelectorQuery):
(WebCore::SelectorQuery::queryAll):
(WebCore::SelectorQuery::queryFirst):
(WebCore::SelectorQuery::canUseIdLookup):
(WebCore::SelectorQuery::execute):

  • dom/SelectorQuery.h: Added.


Class for selector matching in tree.

Location:
trunk/Source/WebCore
Files:
2 added
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r94011 r94089  
    569569    dom/ScriptRunner.cpp
    570570    dom/SelectElement.cpp
    571     dom/SelectorNodeList.cpp
     571    dom/SelectorQuery.cpp
    572572    dom/ShadowContentElement.cpp
    573573    dom/ShadowInclusionSelector.cpp
  • trunk/Source/WebCore/ChangeLog

    r94088 r94089  
     12011-08-30  Antti Koivisto  <antti@apple.com>
     2
     3        querySelector/querySelectorAll should use selector checker fast path
     4        https://bugs.webkit.org/show_bug.cgi?id=67161
     5
     6        Reviewed by Sam Weinig.
     7
     8        Descendant and child selectors can be matches substantially faster using
     9        SelectorChecker::fastCheckSelector() path. Currently it is used for style matching only. 
     10       
     11        Add SelectorQuery class that can do both querySelector and querySelectorAll efficiently using
     12        fast path. Use inlined loop for DOM traversal.
     13       
     14        The patch is ~25% speedup in the overall native score of http://www.webkit.org/perf/slickspeed/.
     15        Some individual subtests (using child or descendant selectors) execute twice as fast.
     16
     17        * CMakeLists.txt:
     18        * GNUmakefile.list.am:
     19        * WebCore.gypi:
     20        * WebCore.pro:
     21        * WebCore.vcproj/WebCore.vcproj:
     22        * WebCore.xcodeproj/project.pbxproj:
     23        * css/CSSStyleSelector.cpp:
     24        (WebCore::CSSStyleSelector::SelectorChecker::checkSelector):
     25        (WebCore::CSSStyleSelector::SelectorChecker::isFastCheckableSelector):
     26        (WebCore::RuleData::RuleData):
     27        * css/CSSStyleSelector.h:
     28       
     29            Make fast path checking available outside CSSStyleSelector.
     30           
     31        * dom/DOMAllInOne.cpp:
     32        * dom/Node.cpp:
     33        (WebCore::Node::querySelector):
     34        (WebCore::Node::querySelectorAll):
     35       
     36            Switch to SelectorQuery.
     37       
     38        * dom/SelectorNodeList.cpp: Removed.
     39        * dom/SelectorNodeList.h: Removed.
     40       
     41            SelectorQuery makes these obsolete.
     42
     43        * dom/SelectorQuery.cpp: Added.
     44        (WebCore::SelectorQuery::SelectorQuery):
     45        (WebCore::SelectorQuery::queryAll):
     46        (WebCore::SelectorQuery::queryFirst):
     47        (WebCore::SelectorQuery::canUseIdLookup):
     48        (WebCore::SelectorQuery::execute):
     49        * dom/SelectorQuery.h: Added.
     50       
     51            Class for selector matching in tree.
     52   
    1532011-08-30  Dmitry Titov  <dimich@chromium.org>
    254
  • trunk/Source/WebCore/GNUmakefile.list.am

    r94083 r94089  
    12851285        Source/WebCore/dom/SelectElement.cpp \
    12861286        Source/WebCore/dom/SelectElement.h \
    1287         Source/WebCore/dom/SelectorNodeList.cpp \
    1288         Source/WebCore/dom/SelectorNodeList.h \
     1287        Source/WebCore/dom/SelectorQuery.cpp \
     1288        Source/WebCore/dom/SelectorQuery.h \
    12891289        Source/WebCore/dom/ShadowContentElement.cpp \
    12901290        Source/WebCore/dom/ShadowContentElement.h \
  • trunk/Source/WebCore/WebCore.gypi

    r94011 r94089  
    53555355            'dom/SelectElement.cpp',
    53565356            'dom/SelectElement.h',
    5357             'dom/SelectorNodeList.cpp',
    5358             'dom/SelectorNodeList.h',
     5357            'dom/SelectorQuery.cpp',
     5358            'dom/SelectorQuery.h',
    53595359            'dom/ShadowContentElement.cpp',
    53605360            'dom/ShadowContentElement.h',
  • trunk/Source/WebCore/WebCore.pro

    r94011 r94089  
    543543    dom/ScriptRunner.cpp \
    544544    dom/SelectElement.cpp \
    545     dom/SelectorNodeList.cpp \
     545    dom/SelectorQuery.cpp \
    546546    dom/ShadowContentElement.cpp \
    547547    dom/ShadowInclusionSelector.cpp \
     
    15371537    dom/ScriptExecutionContext.h \
    15381538    dom/SelectElement.h \
    1539     dom/SelectorNodeList.h \
     1539    dom/SelectorQuery.h \
    15401540    dom/ShadowContentElement.h \
    15411541    dom/ShadowInclusionSelector.h \
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r93951 r94089  
    4833148331                        </File>
    4833248332                        <File
    48333                                 RelativePath="..\dom\SelectorNodeList.cpp"
    48334                                 >
    48335                                 <FileConfiguration
    48336                                         Name="Debug|Win32"
    48337                                         ExcludedFromBuild="true"
    48338                                         >
    48339                                         <Tool
    48340                                                 Name="VCCLCompilerTool"
    48341                                         />
    48342                                 </FileConfiguration>
    48343                                 <FileConfiguration
    48344                                         Name="Release|Win32"
    48345                                         ExcludedFromBuild="true"
    48346                                         >
    48347                                         <Tool
    48348                                                 Name="VCCLCompilerTool"
    48349                                         />
    48350                                 </FileConfiguration>
    48351                                 <FileConfiguration
    48352                                         Name="Debug_Cairo_CFLite|Win32"
    48353                                         ExcludedFromBuild="true"
    48354                                         >
    48355                                         <Tool
    48356                                                 Name="VCCLCompilerTool"
    48357                                         />
    48358                                 </FileConfiguration>
    48359                                 <FileConfiguration
    48360                                         Name="Release_Cairo_CFLite|Win32"
    48361                                         ExcludedFromBuild="true"
    48362                                         >
    48363                                         <Tool
    48364                                                 Name="VCCLCompilerTool"
    48365                                         />
    48366                                 </FileConfiguration>
    48367                                 <FileConfiguration
    48368                                         Name="Debug_All|Win32"
    48369                                         ExcludedFromBuild="true"
    48370                                         >
    48371                                         <Tool
    48372                                                 Name="VCCLCompilerTool"
    48373                                         />
    48374                                 </FileConfiguration>
    48375                                 <FileConfiguration
    48376                                         Name="Production|Win32"
    48377                                         ExcludedFromBuild="true"
    48378                                         >
    48379                                         <Tool
    48380                                                 Name="VCCLCompilerTool"
    48381                                         />
    48382                                 </FileConfiguration>
    48383                         </File>
    48384                         <File
    48385                                 RelativePath="..\dom\SelectorNodeList.cpp"
    48386                                 >
    48387                                 <FileConfiguration
    48388                                         Name="Debug|Win32"
    48389                                         ExcludedFromBuild="true"
    48390                                         >
    48391                                         <Tool
    48392                                                 Name="VCCLCompilerTool"
    48393                                         />
    48394                                 </FileConfiguration>
    48395                                 <FileConfiguration
    48396                                         Name="Release|Win32"
    48397                                         ExcludedFromBuild="true"
    48398                                         >
    48399                                         <Tool
    48400                                                 Name="VCCLCompilerTool"
    48401                                         />
    48402                                 </FileConfiguration>
    48403                                 <FileConfiguration
    48404                                         Name="Debug_Cairo_CFLite|Win32"
    48405                                         ExcludedFromBuild="true"
    48406                                         >
    48407                                         <Tool
    48408                                                 Name="VCCLCompilerTool"
    48409                                         />
    48410                                 </FileConfiguration>
    48411                                 <FileConfiguration
    48412                                         Name="Release_Cairo_CFLite|Win32"
    48413                                         ExcludedFromBuild="true"
    48414                                         >
    48415                                         <Tool
    48416                                                 Name="VCCLCompilerTool"
    48417                                         />
    48418                                 </FileConfiguration>
    48419                                 <FileConfiguration
    48420                                         Name="Debug_All|Win32"
    48421                                         ExcludedFromBuild="true"
    48422                                         >
    48423                                         <Tool
    48424                                                 Name="VCCLCompilerTool"
    48425                                         />
    48426                                 </FileConfiguration>
    48427                                 <FileConfiguration
    48428                                         Name="Production|Win32"
    48429                                         ExcludedFromBuild="true"
    48430                                         >
    48431                                         <Tool
    48432                                                 Name="VCCLCompilerTool"
    48433                                         />
    48434                                 </FileConfiguration>
    48435                         </File>
    48436                         <File
    48437                                 RelativePath="..\dom\SelectorNodeList.h"
    48438                                 >
    48439                         </File>
    48440                         <File
    48441                                 RelativePath="..\dom\SelectorNodeList.h"
     48333                                RelativePath="..\dom\SelectorQuery.cpp"
     48334                                >
     48335                                <FileConfiguration
     48336                                        Name="Debug|Win32"
     48337                                        ExcludedFromBuild="true"
     48338                                        >
     48339                                        <Tool
     48340                                                Name="VCCLCompilerTool"
     48341                                        />
     48342                                </FileConfiguration>
     48343                                <FileConfiguration
     48344                                        Name="Release|Win32"
     48345                                        ExcludedFromBuild="true"
     48346                                        >
     48347                                        <Tool
     48348                                                Name="VCCLCompilerTool"
     48349                                        />
     48350                                </FileConfiguration>
     48351                                <FileConfiguration
     48352                                        Name="Debug_Cairo_CFLite|Win32"
     48353                                        ExcludedFromBuild="true"
     48354                                        >
     48355                                        <Tool
     48356                                                Name="VCCLCompilerTool"
     48357                                        />
     48358                                </FileConfiguration>
     48359                                <FileConfiguration
     48360                                        Name="Release_Cairo_CFLite|Win32"
     48361                                        ExcludedFromBuild="true"
     48362                                        >
     48363                                        <Tool
     48364                                                Name="VCCLCompilerTool"
     48365                                        />
     48366                                </FileConfiguration>
     48367                                <FileConfiguration
     48368                                        Name="Debug_All|Win32"
     48369                                        ExcludedFromBuild="true"
     48370                                        >
     48371                                        <Tool
     48372                                                Name="VCCLCompilerTool"
     48373                                        />
     48374                                </FileConfiguration>
     48375                                <FileConfiguration
     48376                                        Name="Production|Win32"
     48377                                        ExcludedFromBuild="true"
     48378                                        >
     48379                                        <Tool
     48380                                                Name="VCCLCompilerTool"
     48381                                        />
     48382                                </FileConfiguration>
     48383                        </File>
     48384                        <File
     48385                                RelativePath="..\dom\SelectorQuery.h"
    4844248386                                >
    4844348387                        </File>
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r94011 r94089  
    50995099                BC7FA62D0D1F0EFF00DB22A9 /* StaticNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = BC7FA62B0D1F0EFF00DB22A9 /* StaticNodeList.h */; };
    51005100                BC7FA62E0D1F0EFF00DB22A9 /* StaticNodeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC7FA62C0D1F0EFF00DB22A9 /* StaticNodeList.cpp */; };
    5101                 BC7FA6810D1F167900DB22A9 /* SelectorNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = BC7FA67F0D1F167900DB22A9 /* SelectorNodeList.h */; };
    5102                 BC7FA6820D1F167900DB22A9 /* SelectorNodeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC7FA6800D1F167900DB22A9 /* SelectorNodeList.cpp */; };
    51035101                BC80C9870CD294EE00A0B7B3 /* CSSTimingFunctionValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC80C9850CD294EE00A0B7B3 /* CSSTimingFunctionValue.cpp */; };
    51045102                BC80C9880CD294EE00A0B7B3 /* CSSTimingFunctionValue.h in Headers */ = {isa = PBXBuildFile; fileRef = BC80C9860CD294EE00A0B7B3 /* CSSTimingFunctionValue.h */; };
     
    56535651                E44614510CD68A3500FADA75 /* RenderVideo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B41E330CBFB60900AF2ECE /* RenderVideo.cpp */; };
    56545652                E44614520CD68A3500FADA75 /* RenderVideo.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B41E340CBFB60900AF2ECE /* RenderVideo.h */; };
     5653                E45322AB140CE267005A0F92 /* SelectorQuery.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E45322A9140CE267005A0F92 /* SelectorQuery.cpp */; };
     5654                E45322AC140CE267005A0F92 /* SelectorQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = E45322AA140CE267005A0F92 /* SelectorQuery.h */; };
    56555655                E462A4A1113E71BE004A4220 /* IntPointHash.h in Headers */ = {isa = PBXBuildFile; fileRef = E462A4A0113E71BE004A4220 /* IntPointHash.h */; settings = {ATTRIBUTES = (Private, ); }; };
    56565656                E4778B7F115A581A00B5D372 /* JSCustomEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4778B7D115A581A00B5D372 /* JSCustomEvent.cpp */; };
     
    1181811818                BC7FA62B0D1F0EFF00DB22A9 /* StaticNodeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StaticNodeList.h; sourceTree = "<group>"; };
    1181911819                BC7FA62C0D1F0EFF00DB22A9 /* StaticNodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StaticNodeList.cpp; sourceTree = "<group>"; };
    11820                 BC7FA67F0D1F167900DB22A9 /* SelectorNodeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectorNodeList.h; sourceTree = "<group>"; };
    11821                 BC7FA6800D1F167900DB22A9 /* SelectorNodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectorNodeList.cpp; sourceTree = "<group>"; };
    1182211820                BC80C9850CD294EE00A0B7B3 /* CSSTimingFunctionValue.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CSSTimingFunctionValue.cpp; sourceTree = "<group>"; };
    1182311821                BC80C9860CD294EE00A0B7B3 /* CSSTimingFunctionValue.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CSSTimingFunctionValue.h; sourceTree = "<group>"; };
     
    1240612404                E44614120CD6826900FADA75 /* JSTimeRanges.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTimeRanges.cpp; sourceTree = "<group>"; };
    1240712405                E44614130CD6826900FADA75 /* JSTimeRanges.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTimeRanges.h; sourceTree = "<group>"; };
     12406                E45322A9140CE267005A0F92 /* SelectorQuery.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectorQuery.cpp; sourceTree = "<group>"; };
     12407                E45322AA140CE267005A0F92 /* SelectorQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectorQuery.h; sourceTree = "<group>"; };
    1240812408                E462A4A0113E71BE004A4220 /* IntPointHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntPointHash.h; sourceTree = "<group>"; };
    1240912409                E4778B7D115A581A00B5D372 /* JSCustomEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomEvent.cpp; sourceTree = "<group>"; };
     
    2006320063                                084AEBE20FB505FA0038483E /* SelectElement.cpp */,
    2006420064                                084AEBE30FB505FA0038483E /* SelectElement.h */,
    20065                                 BC7FA6800D1F167900DB22A9 /* SelectorNodeList.cpp */,
    20066                                 BC7FA67F0D1F167900DB22A9 /* SelectorNodeList.h */,
     20065                                E45322A9140CE267005A0F92 /* SelectorQuery.cpp */,
     20066                                E45322AA140CE267005A0F92 /* SelectorQuery.h */,
    2006720067                                A766CF8B13810E0C0011A0B3 /* ShadowContentElement.cpp */,
    2006820068                                A74C2D3B13811E0D00F83572 /* ShadowContentElement.h */,
     
    2284022840                                B2C3DA2F0D006C1D00EF6F26 /* SegmentedString.h in Headers */,
    2284122841                                084AEBE50FB505FA0038483E /* SelectElement.h in Headers */,
    22842                                 BC7FA6810D1F167900DB22A9 /* SelectorNodeList.h in Headers */,
    2284322842                                A75E497610752ACB00C9B896 /* SerializedScriptValue.h in Headers */,
    2284422843                                93309E10099E64920056E581 /* SetNodeAttributeCommand.h in Headers */,
     
    2344923448                                D0A3A7311405A39800FB8ED3 /* ResourceLoaderOptions.h in Headers */,
    2345023449                                BCE43897140B0051005E437E /* EventConstructors.h in Headers */,
     23450                                E45322AC140CE267005A0F92 /* SelectorQuery.h in Headers */,
    2345123451                                B10B6980140C174000BC1C26 /* WebVTTToken.h in Headers */,
    2345223452                                B10B6982140C174000BC1C26 /* WebVTTTokenizer.h in Headers */,
     
    2578225782                                B2C3DA2E0D006C1D00EF6F26 /* SegmentedString.cpp in Sources */,
    2578325783                                084AEBE40FB505FA0038483E /* SelectElement.cpp in Sources */,
    25784                                 BC7FA6820D1F167900DB22A9 /* SelectorNodeList.cpp in Sources */,
    2578525784                                A75E497710752ACB00C9B896 /* SerializedScriptValue.cpp in Sources */,
    2578625785                                93309E0F099E64920056E581 /* SetNodeAttributeCommand.cpp in Sources */,
     
    2626026259                                DF9AFD7313FC31D80015FEB7 /* MediaPlayerPrivateAVFoundationObjC.mm in Sources */,
    2626126260                                BCE4389A140B0073005E437E /* JSEventConstructors.cpp in Sources */,
     26261                                E45322AB140CE267005A0F92 /* SelectorQuery.cpp in Sources */,
    2626226262                                B10B6981140C174000BC1C26 /* WebVTTTokenizer.cpp in Sources */,
    2626326263                        );
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r94037 r94089  
    876876}
    877877
    878 bool CSSStyleSelector::SelectorChecker::checkSelector(CSSSelector* sel, Element* element) const
     878bool CSSStyleSelector::SelectorChecker::checkSelector(CSSSelector* sel, Element* element, bool isFastCheckableSelector) const
    879879{
    880880    PseudoId dynamicPseudo = NOPSEUDO;
     881    if (isFastCheckableSelector && !element->isSVGElement()) {
     882        // fastCheckSelector assumes class and id match for the top selector.
     883        if (sel->m_match == CSSSelector::Class) {
     884            if (!(element->hasClass() && static_cast<StyledElement*>(element)->classNames().contains(sel->value())))
     885                return false;
     886        } else if (sel->m_match == CSSSelector::Id) {
     887            if (!(element->hasID() && element->idForStyleResolution() == sel->value()))
     888                return false;
     889        }
     890        return fastCheckSelector(sel, element);
     891    }
    881892    return checkSelector(sel, element, dynamicPseudo, false, false) == SelectorMatches;
    882893}
     
    20132024    return namespaceURI == starAtom || namespaceURI == element->namespaceURI();
    20142025}
    2015 
    2016 inline bool isFastCheckableSelector(const CSSSelector* selector)
    2017 {
    2018     for (; selector; selector = selector->tagHistory()) {
    2019         if (selector->relation() != CSSSelector::Descendant && selector->relation() != CSSSelector::Child && selector->relation() != CSSSelector::SubSelector)
    2020             return false;
    2021         if (selector->m_match != CSSSelector::None && selector->m_match != CSSSelector::Id && selector->m_match != CSSSelector::Class)
    2022             return false;
    2023     }
    2024     return true;
    2025 }
    20262026   
    20272027template <bool checkValue(const Element*, AtomicStringImpl*)>
     
    21132113            ASSERT_NOT_REACHED();
    21142114        }
     2115    }
     2116    return true;
     2117}
     2118
     2119bool CSSStyleSelector::SelectorChecker::isFastCheckableSelector(const CSSSelector* selector)
     2120{
     2121    for (; selector; selector = selector->tagHistory()) {
     2122        if (selector->relation() != CSSSelector::Descendant && selector->relation() != CSSSelector::Child && selector->relation() != CSSSelector::SubSelector)
     2123            return false;
     2124        if (selector->m_match != CSSSelector::None && selector->m_match != CSSSelector::Id && selector->m_match != CSSSelector::Class)
     2125            return false;
    21152126    }
    21162127    return true;
     
    30363047    , m_specificity(selector->specificity())
    30373048    , m_position(position)
    3038     , m_hasFastCheckableSelector(isFastCheckableSelector(selector))
     3049    , m_hasFastCheckableSelector(CSSStyleSelector::SelectorChecker::isFastCheckableSelector(selector))
    30393050    , m_hasMultipartSelector(selector->tagHistory())
    30403051    , m_hasTopSelectorMatchingHTMLBasedOnRuleHash(isSelectorMatchingHTMLBasedOnRuleHash(selector))
  • trunk/Source/WebCore/css/CSSStyleSelector.h

    r93218 r94089  
    276276            SelectorChecker(Document*, bool strictParsing);
    277277
    278             bool checkSelector(CSSSelector*, Element*) const;
     278            bool checkSelector(CSSSelector*, Element*, bool isFastCheckableSelector = false) const;
    279279            SelectorMatch checkSelector(CSSSelector*, Element*, PseudoId& dynamicPseudo, bool isSubSelector, bool encounteredLink, RenderStyle* = 0, RenderStyle* elementParentStyle = 0) const;
    280280            bool checkOneSelector(CSSSelector*, Element*, PseudoId& dynamicPseudo, bool isSubSelector, bool encounteredLink, RenderStyle*, RenderStyle* elementParentStyle) const;
    281281            bool checkScrollbarPseudoClass(CSSSelector*, PseudoId& dynamicPseudo) const;
     282            static bool isFastCheckableSelector(const CSSSelector*);
    282283            static bool fastCheckSelector(const CSSSelector*, const Element*);
    283284
  • trunk/Source/WebCore/dom/DOMAllInOne.cpp

    r93411 r94089  
    116116#include "ScriptableDocumentParser.cpp"
    117117#include "SelectElement.cpp"
    118 #include "SelectorNodeList.cpp"
     118#include "SelectorQuery.cpp"
    119119#include "ShadowContentElement.cpp"
    120120#include "ShadowInclusionSelector.cpp"
  • trunk/Source/WebCore/dom/Node.cpp

    r93481 r94089  
    8282#include "RenderView.h"
    8383#include "ScopedEventQueue.h"
    84 #include "SelectorNodeList.h"
     84#include "SelectorQuery.h"
    8585#include "ShadowRoot.h"
    8686#include "StaticNodeList.h"
     
    17661766        return 0;
    17671767    }
    1768 
    1769     CSSStyleSelector::SelectorChecker selectorChecker(document(), strictParsing);
    1770 
    1771     // FIXME: we could also optimize for the the [id="foo"] case
    1772     if (strictParsing && inDocument() && querySelectorList.hasOneSelector() && querySelectorList.first()->m_match == CSSSelector::Id) {
    1773         Element* element = treeScope()->getElementById(querySelectorList.first()->value());
    1774         if (element && (isDocumentNode() || element->isDescendantOf(this)) && selectorChecker.checkSelector(querySelectorList.first(), element))
    1775             return element;
    1776         return 0;
    1777     }
    1778 
    1779     // FIXME: We can speed this up by implementing caching similar to the one use by getElementById
    1780     for (Node* n = firstChild(); n; n = n->traverseNextNode(this)) {
    1781         if (n->isElementNode()) {
    1782             Element* element = static_cast<Element*>(n);
    1783             for (CSSSelector* selector = querySelectorList.first(); selector; selector = CSSSelectorList::next(selector)) {
    1784                 if (selectorChecker.checkSelector(selector, element))
    1785                     return element;
    1786             }
    1787         }
    1788     }
    1789    
    1790     return 0;
     1768   
     1769    SelectorQuery selectorQuery(this, querySelectorList);
     1770    return selectorQuery.queryFirst();
    17911771}
    17921772
     
    18141794    }
    18151795
    1816     return createSelectorNodeList(this, querySelectorList);
     1796    SelectorQuery selectorQuery(this, querySelectorList);
     1797    return selectorQuery.queryAll();
    18171798}
    18181799
Note: See TracChangeset for help on using the changeset viewer.