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

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

Issue 2553343002: Avoid WTF::Vector::at() and operator[] in core/dom. (Closed)
Patch Set: Created 4 years 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
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 bb2599bfc3bd0f009d8d3a5e8278a72d2cea89a3..b07c63627047d7e983aa8e59780f950c77e8f249 100644
--- a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
+++ b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
@@ -145,9 +145,8 @@ bool SelectorDataList::matches(Element& targetElement) const {
if (m_needsUpdatedDistribution)
targetElement.updateDistribution();
- unsigned selectorCount = m_selectors.size();
- for (unsigned i = 0; i < selectorCount; ++i) {
- if (selectorMatches(*m_selectors[i], targetElement, targetElement))
+ for (const auto& selector : m_selectors) {
+ if (selectorMatches(*selector, targetElement, targetElement))
return true;
}
@@ -155,16 +154,15 @@ bool SelectorDataList::matches(Element& targetElement) const {
}
Element* SelectorDataList::closest(Element& targetElement) const {
- unsigned selectorCount = m_selectors.size();
- if (!selectorCount)
+ if (m_selectors.size() == 0)
return nullptr;
if (m_needsUpdatedDistribution)
targetElement.updateDistribution();
for (Element* currentElement = &targetElement; currentElement;
currentElement = currentElement->parentElement()) {
- for (unsigned i = 0; i < selectorCount; ++i) {
- if (selectorMatches(*m_selectors[i], *currentElement, targetElement))
+ for (const auto& selector : m_selectors) {
+ if (selectorMatches(*selector, *currentElement, targetElement))
return currentElement;
}
}
@@ -409,8 +407,8 @@ bool SelectorDataList::selectorListMatches(
ContainerNode& rootNode,
Element& element,
typename SelectorQueryTrait::OutputType& output) const {
- for (unsigned i = 0; i < m_selectors.size(); ++i) {
- if (selectorMatches(*m_selectors[i], element, rootNode)) {
+ for (const auto& selector : m_selectors) {
+ if (selectorMatches(*selector, element, rootNode)) {
SelectorQueryTrait::appendElement(output, element);
return true;
}
@@ -546,13 +544,11 @@ void SelectorDataList::execute(
if (rootNode.treeScope().containsMultipleElementsWithId(idToMatch)) {
const HeapVector<Member<Element>>& elements =
rootNode.treeScope().getAllElementsById(idToMatch);
- size_t count = elements.size();
- for (size_t i = 0; i < count; ++i) {
- Element& element = *elements[i];
- if (!(isTreeScopeRoot(rootNode) || element.isDescendantOf(&rootNode)))
+ for (const auto& element : elements) {
+ if (!(isTreeScopeRoot(rootNode) || element->isDescendantOf(&rootNode)))
continue;
- if (selectorMatches(selector, element, rootNode)) {
- SelectorQueryTrait::appendElement(output, element);
+ if (selectorMatches(selector, *element, rootNode)) {
+ SelectorQueryTrait::appendElement(output, *element);
if (SelectorQueryTrait::shouldOnlyMatchFirstElement)
return;
}

Powered by Google App Engine
This is Rietveld 408576698