Optimized querySelector(All) when selector contains #id
[WebKit-https.git] / Source / WebCore / dom / SelectorQuery.h
index 3119120cd8dd90169c4cf35bbcbc9881b7e6ea67..c6769a76f9cebe23172a3d2194817fd131b50686 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2013, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -46,21 +46,25 @@ class NodeList;
 
 class SelectorDataList {
 public:
-    void initialize(const CSSSelectorList&);
+    explicit SelectorDataList(const CSSSelectorList&);
     bool matches(Element&) const;
     RefPtr<NodeList> queryAll(ContainerNode& rootNode) const;
     Element* queryFirst(ContainerNode& rootNode) const;
 
 private:
     struct SelectorData {
-        SelectorData(const CSSSelector* selector, bool isFastCheckable) : selector(selector), isFastCheckable(isFastCheckable) { }
-        const CSSSelector* selector;
-        bool isFastCheckable;
+        SelectorData(const CSSSelector* selector, bool isFastCheckable)
+            : selector(selector)
+            , isFastCheckable(isFastCheckable)
+        {
+        }
 
+        const CSSSelector* selector;
 #if ENABLE(CSS_SELECTOR_JIT)
-        mutable SelectorCompilationStatus compilationStatus;
         mutable JSC::MacroAssemblerCodeRef compiledSelectorCodeRef;
+        mutable SelectorCompilationStatus compilationStatus;
 #endif // ENABLE(CSS_SELECTOR_JIT)
+        bool isFastCheckable;
     };
 
     bool selectorMatches(const SelectorData&, Element&, const ContainerNode& rootNode) const;
@@ -73,10 +77,20 @@ private:
     template <typename SelectorQueryTrait> void executeSingleMultiSelectorData(const ContainerNode& rootNode, typename SelectorQueryTrait::OutputType&) const;
 #if ENABLE(CSS_SELECTOR_JIT)
     template <typename SelectorQueryTrait> void executeCompiledSimpleSelectorChecker(const ContainerNode& rootNode, SelectorCompiler::SimpleSelectorChecker, typename SelectorQueryTrait::OutputType&) const;
-    template <typename SelectorQueryTrait> void executeCompiledSelectorCheckerWithContext(const ContainerNode& rootNode, SelectorCompiler::SelectorCheckerWithCheckingContext, const SelectorCompiler::CheckingContext&, typename SelectorQueryTrait::OutputType&) const;
 #endif // ENABLE(CSS_SELECTOR_JIT)
 
     Vector<SelectorData> m_selectors;
+    mutable enum MatchType {
+        CompilableSingle,
+        CompilableSingleWithRootFilter,
+        CompiledSingle,
+        CompiledSingleWithRootFilter,
+        SingleSelector,
+        RightMostWithIdMatch,
+        TagNameMatch,
+        ClassNameMatch,
+        MultipleSelectorMatch,
+    } m_matchType;
 };
 
 class SelectorQuery {
@@ -84,14 +98,14 @@ class SelectorQuery {
     WTF_MAKE_FAST_ALLOCATED;
 
 public:
-    explicit SelectorQuery(const CSSSelectorList&);
+    explicit SelectorQuery(CSSSelectorList&&);
     bool matches(Element&) const;
     RefPtr<NodeList> queryAll(ContainerNode& rootNode) const;
     Element* queryFirst(ContainerNode& rootNode) const;
 
 private:
-    SelectorDataList m_selectors;
     CSSSelectorList m_selectorList;
+    SelectorDataList m_selectors;
 };
 
 class SelectorQueryCache {