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

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

Issue 149513011: Pass around CSSSelector by reference instead of pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 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 | « Source/core/dom/SelectorQuery.h ('k') | Source/core/dom/shadow/ElementShadow.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/SelectorQuery.cpp
diff --git a/Source/core/dom/SelectorQuery.cpp b/Source/core/dom/SelectorQuery.cpp
index 69d7dfa6de44c6ed1d45912b72a344d2b7ee634a..460efd20200721da4d96a0dbe947fd5fcc7dabfd 100644
--- a/Source/core/dom/SelectorQuery.cpp
+++ b/Source/core/dom/SelectorQuery.cpp
@@ -101,12 +101,12 @@ void SelectorDataList::initialize(const CSSSelectorList& selectorList)
ASSERT(m_selectors.isEmpty());
unsigned selectorCount = 0;
- for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(selector))
+ for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(*selector))
selectorCount++;
m_selectors.reserveInitialCapacity(selectorCount);
- for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(selector))
- m_selectors.uncheckedAppend(SelectorData(selector, SelectorCheckerFastPath::canUse(selector)));
+ for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(*selector))
+ m_selectors.uncheckedAppend(SelectorData(*selector, SelectorCheckerFastPath::canUse(*selector)));
}
inline bool SelectorDataList::selectorMatches(const SelectorData& selectorData, Element& element, const ContainerNode& rootNode) const
@@ -205,12 +205,11 @@ void SelectorDataList::findTraverseRootsAndExecute(ContainerNode& rootNode, type
// We need to return the matches in document order. To use id lookup while there is possiblity of multiple matches
// we would need to sort the results. For now, just traverse the document in that case.
ASSERT(m_selectors.size() == 1);
- ASSERT(m_selectors[0].selector);
bool isRightmostSelector = true;
bool startFromParent = false;
- for (const CSSSelector* selector = m_selectors[0].selector; selector; selector = selector->tagHistory()) {
+ for (const CSSSelector* selector = &m_selectors[0].selector; selector; selector = selector->tagHistory()) {
if (selector->m_match == CSSSelector::Id && !rootNode.document().containsMultipleElementsWithId(selector->value())) {
Element* element = rootNode.treeScope().getElementById(selector->value());
ContainerNode* adjustedNode = &rootNode;
@@ -329,9 +328,9 @@ void SelectorDataList::executeSlow(ContainerNode& rootNode, typename SelectorQue
}
}
-const CSSSelector* SelectorDataList::selectorForIdLookup(const CSSSelector* firstSelector) const
+const CSSSelector* SelectorDataList::selectorForIdLookup(const CSSSelector& firstSelector) const
{
- for (const CSSSelector* selector = firstSelector; selector; selector = selector->tagHistory()) {
+ for (const CSSSelector* selector = &firstSelector; selector; selector = selector->tagHistory()) {
if (selector->m_match == CSSSelector::Id)
return selector;
if (selector->relation() != CSSSelector::SubSelector)
@@ -349,10 +348,9 @@ void SelectorDataList::execute(ContainerNode& rootNode, typename SelectorQueryTr
}
ASSERT(m_selectors.size() == 1);
- ASSERT(m_selectors[0].selector);
const SelectorData& selector = m_selectors[0];
- const CSSSelector* firstSelector = selector.selector;
+ const CSSSelector& firstSelector = selector.selector;
// Fast path for querySelector*('#id'), querySelector*('tag#id').
if (const CSSSelector* idSelector = selectorForIdLookup(firstSelector)) {
@@ -380,14 +378,14 @@ void SelectorDataList::execute(ContainerNode& rootNode, typename SelectorQueryTr
return;
}
- if (!firstSelector->tagHistory()) {
+ if (!firstSelector.tagHistory()) {
// Fast path for querySelector*('.foo'), and querySelector*('div').
- switch (firstSelector->m_match) {
+ switch (firstSelector.m_match) {
case CSSSelector::Class:
- collectElementsByClassName<SelectorQueryTrait>(rootNode, firstSelector->value(), output);
+ collectElementsByClassName<SelectorQueryTrait>(rootNode, firstSelector.value(), output);
return;
case CSSSelector::Tag:
- collectElementsByTagName<SelectorQueryTrait>(rootNode, firstSelector->tagQName(), output);
+ collectElementsByTagName<SelectorQueryTrait>(rootNode, firstSelector.tagQName(), output);
return;
default:
break; // If we need another fast path, add here.
« no previous file with comments | « Source/core/dom/SelectorQuery.h ('k') | Source/core/dom/shadow/ElementShadow.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698