Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: Source/core/dom/SelectorQuery.h

Issue 18732004: Add fast path for querySelector(All) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Patch for landing (rebased) Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « PerformanceTests/Parser/query-selector-all-last.html ('k') | Source/core/dom/SelectorQuery.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 22 matching lines...) Expand all
33 33
34 namespace WebCore { 34 namespace WebCore {
35 35
36 typedef int ExceptionCode; 36 typedef int ExceptionCode;
37 37
38 class CSSSelector; 38 class CSSSelector;
39 class Document; 39 class Document;
40 class Element; 40 class Element;
41 class Node; 41 class Node;
42 class NodeList; 42 class NodeList;
43 class SimpleNodeList;
44 class SpaceSplitString;
43 45
44 class SelectorDataList { 46 class SelectorDataList {
45 public: 47 public:
46 void initialize(const CSSSelectorList&); 48 void initialize(const CSSSelectorList&);
47 bool matches(Element*) const; 49 bool matches(Element*) const;
48 PassRefPtr<NodeList> queryAll(Node* rootNode) const; 50 PassRefPtr<NodeList> queryAll(Node* rootNode) const;
49 PassRefPtr<Element> queryFirst(Node* rootNode) const; 51 PassRefPtr<Element> queryFirst(Node* rootNode) const;
50 52
51 private: 53 private:
52 struct SelectorData { 54 struct SelectorData {
53 SelectorData(const CSSSelector* selector, bool isFastCheckable) : select or(selector), isFastCheckable(isFastCheckable) { } 55 SelectorData(const CSSSelector* selector, bool isFastCheckable) : select or(selector), isFastCheckable(isFastCheckable) { }
54 const CSSSelector* selector; 56 const CSSSelector* selector;
55 bool isFastCheckable; 57 bool isFastCheckable;
56 }; 58 };
57 59
60 bool canUseFastQuery(Node* rootNode) const;
58 bool selectorMatches(const SelectorData&, Element*, const Node*) const; 61 bool selectorMatches(const SelectorData&, Element*, const Node*) const;
59 std::pair<bool, Node*> findTraverseRoot(Node* traverseRoot) const; 62 void collectElementsByClassName(Node* rootNode, const AtomicString& classNam e, Vector<RefPtr<Node> >&) const;
60 template <bool firstMatchOnly> 63 Element* findElementByClassName(Node* rootNode, const AtomicString& classNam e) const;
61 void execute(Node* rootNode, Vector<RefPtr<Node> >&) const; 64 void collectElementsByTagName(Node* rootNode, const QualifiedName& tagName, Vector<RefPtr<Node> >&) const;
65 Element* findElementByTagName(Node* rootNode, const QualifiedName& tagName) const;
66 PassOwnPtr<SimpleNodeList> findTraverseRoots(Node* rootNode, bool& matchTrav erseRoots) const;
67 void executeSlowQueryAll(Node* rootNode, Vector<RefPtr<Node> >& matchedEleme nts) const;
68 void executeQueryAll(Node* rootNode, Vector<RefPtr<Node> >& matchedElements) const;
69 Node* findTraverseRoot(Node* rootNode, bool& matchTraverseRoot) const;
70 Element* executeSlowQueryFirst(Node* rootNode) const;
71 Element* executeQueryFirst(Node* rootNode) const;
62 72
63 Vector<SelectorData> m_selectors; 73 Vector<SelectorData> m_selectors;
64 }; 74 };
65 75
66 class SelectorQuery { 76 class SelectorQuery {
67 WTF_MAKE_NONCOPYABLE(SelectorQuery); 77 WTF_MAKE_NONCOPYABLE(SelectorQuery);
68 WTF_MAKE_FAST_ALLOCATED; 78 WTF_MAKE_FAST_ALLOCATED;
69 public: 79 public:
70 explicit SelectorQuery(const CSSSelectorList&); 80 explicit SelectorQuery(const CSSSelectorList&);
71 bool matches(Element*) const; 81 bool matches(Element*) const;
(...skipping 10 matching lines...) Expand all
82 SelectorQuery* add(const AtomicString&, Document*, ExceptionCode&); 92 SelectorQuery* add(const AtomicString&, Document*, ExceptionCode&);
83 void invalidate(); 93 void invalidate();
84 94
85 private: 95 private:
86 HashMap<AtomicString, OwnPtr<SelectorQuery> > m_entries; 96 HashMap<AtomicString, OwnPtr<SelectorQuery> > m_entries;
87 }; 97 };
88 98
89 } 99 }
90 100
91 #endif 101 #endif
OLDNEW
« no previous file with comments | « PerformanceTests/Parser/query-selector-all-last.html ('k') | Source/core/dom/SelectorQuery.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698