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

Unified Diff: third_party/WebKit/Source/core/dom/SelectorQuery.cpp

Issue 2791473002: Reuse selectorListMatches for all loops over the selectors in SelectorQuery. (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/SelectorQuery.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/SelectorQuery.cpp
diff --git a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
index 179af326688c79a32b66f4b4c9d1d47a9e46e1b0..83557a094682b77d725f592402854b7f2b5b92b4 100644
--- a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
+++ b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
@@ -121,13 +121,7 @@ inline bool selectorMatches(const CSSSelector& selector,
bool SelectorQuery::matches(Element& targetElement) const {
if (m_needsUpdatedDistribution)
targetElement.updateDistribution();
-
- for (const auto& selector : m_selectors) {
- if (selectorMatches(*selector, targetElement, targetElement))
- return true;
- }
-
- return false;
+ return selectorListMatches(targetElement, targetElement);
}
Element* SelectorQuery::closest(Element& targetElement) const {
@@ -138,10 +132,8 @@ Element* SelectorQuery::closest(Element& targetElement) const {
for (Element* currentElement = &targetElement; currentElement;
currentElement = currentElement->parentElement()) {
- for (const auto& selector : m_selectors) {
- if (selectorMatches(*selector, *currentElement, targetElement))
- return currentElement;
- }
+ if (selectorListMatches(targetElement, *currentElement))
+ return currentElement;
}
return nullptr;
}
@@ -326,16 +318,11 @@ void SelectorQuery::executeForTraverseRoot(
}
}
-template <typename SelectorQueryTrait>
-bool SelectorQuery::selectorListMatches(
- ContainerNode& rootNode,
- Element& element,
- typename SelectorQueryTrait::OutputType& output) const {
+bool SelectorQuery::selectorListMatches(ContainerNode& rootNode,
+ Element& element) const {
for (const auto& selector : m_selectors) {
- if (selectorMatches(*selector, element, rootNode)) {
- SelectorQueryTrait::appendElement(output, element);
+ if (selectorMatches(*selector, element, rootNode))
return true;
- }
}
return false;
}
@@ -345,8 +332,10 @@ void SelectorQuery::executeSlow(
ContainerNode& rootNode,
typename SelectorQueryTrait::OutputType& output) const {
for (Element& element : ElementTraversal::descendantsOf(rootNode)) {
- if (selectorListMatches<SelectorQueryTrait>(rootNode, element, output) &&
- SelectorQueryTrait::shouldOnlyMatchFirstElement)
+ if (!selectorListMatches(rootNode, element))
+ continue;
+ SelectorQueryTrait::appendElement(output, element);
+ if (SelectorQueryTrait::shouldOnlyMatchFirstElement)
return;
}
}
@@ -404,8 +393,10 @@ void SelectorQuery::executeSlowTraversingShadowTree(
if (!node->isElementNode())
continue;
Element* element = toElement(node);
- if (selectorListMatches<SelectorQueryTrait>(rootNode, *element, output) &&
- SelectorQueryTrait::shouldOnlyMatchFirstElement)
+ if (!selectorListMatches(rootNode, *element))
+ continue;
+ SelectorQueryTrait::appendElement(output, *element);
+ if (SelectorQueryTrait::shouldOnlyMatchFirstElement)
return;
}
}
« no previous file with comments | « third_party/WebKit/Source/core/dom/SelectorQuery.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698