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

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

Issue 2774663003: Simplify the SelectorQuery constructor and reuse CSSSelectorList::length(). (Closed)
Patch Set: woops 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 e38f50746fb9f7f81fb34e3991c0e9fa1cea987b..c3b21eaf16a107279503dd0a3b05dbbb413c683b 100644
--- a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
+++ b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
@@ -131,7 +131,7 @@ bool SelectorQuery::matches(Element& targetElement) const {
}
Element* SelectorQuery::closest(Element& targetElement) const {
- if (m_selectors.size() == 0)
+ if (m_selectors.isEmpty())
return nullptr;
if (m_needsUpdatedDistribution)
targetElement.updateDistribution();
@@ -559,18 +559,11 @@ std::unique_ptr<SelectorQuery> SelectorQuery::adopt(
return WTF::wrapUnique(new SelectorQuery(std::move(selectorList)));
}
-SelectorQuery::SelectorQuery(CSSSelectorList selectorList) {
- m_selectorList = std::move(selectorList);
- DCHECK(m_selectors.isEmpty());
-
- unsigned selectorCount = 0;
- for (const CSSSelector* selector = m_selectorList.first(); selector;
- selector = CSSSelectorList::next(*selector))
- selectorCount++;
-
- m_usesDeepCombinatorOrShadowPseudo = false;
- m_needsUpdatedDistribution = false;
- m_selectors.reserveInitialCapacity(selectorCount);
+SelectorQuery::SelectorQuery(CSSSelectorList selectorList)
+ : m_selectorList(std::move(selectorList)),
+ m_usesDeepCombinatorOrShadowPseudo(false),
+ m_needsUpdatedDistribution(false) {
+ m_selectors.reserveInitialCapacity(m_selectorList.computeLength());
for (const CSSSelector* selector = m_selectorList.first(); selector;
selector = CSSSelectorList::next(*selector)) {
if (selector->matchesPseudoElement())
« 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