Commit cd631cd8 authored by Morten Stenshorne's avatar Morten Stenshorne Committed by Commit Bot

Don't walk the list of documents while already doing it.

There should be no need to walk all documents in an inner loop while
already doing it in the outer loop.

The O(n^2) performance complexity is probably negligible, but what I'm
actually trying to fix here is problems when compiling with -Wshadow
(the problem here being the various |document| variables).

Bug: 294205
Change-Id: Ide1ab566e3b9ddb53d4b4f44c9c03633c90348a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2460745Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816260}
parent 7012ae8a
......@@ -1144,42 +1144,41 @@ Response InspectorDOMAgent::performSearch(
break;
}
}
}
// XPath evaluation
for (Document* document : docs) {
DCHECK(document);
DummyExceptionStateForTesting exception_state;
XPathResult* result = DocumentXPathEvaluator::evaluate(
*document, whitespace_trimmed_query, document, nullptr,
XPathResult::kOrderedNodeSnapshotType, ScriptValue(),
exception_state);
if (exception_state.HadException() || !result)
continue;
// XPath evaluation
for (Document* document : docs) {
DCHECK(document);
DummyExceptionStateForTesting exception_state;
XPathResult* result = DocumentXPathEvaluator::evaluate(
*document, whitespace_trimmed_query, document, nullptr,
XPathResult::kOrderedNodeSnapshotType, ScriptValue(), exception_state);
if (exception_state.HadException() || !result)
continue;
wtf_size_t size = result->snapshotLength(exception_state);
for (wtf_size_t i = 0; !exception_state.HadException() && i < size; ++i) {
Node* node = result->snapshotItem(i, exception_state);
if (exception_state.HadException())
break;
wtf_size_t size = result->snapshotLength(exception_state);
for (wtf_size_t i = 0; !exception_state.HadException() && i < size; ++i) {
Node* node = result->snapshotItem(i, exception_state);
if (exception_state.HadException())
break;
if (node->getNodeType() == Node::kAttributeNode)
node = To<Attr>(node)->ownerElement();
result_collector.insert(node);
}
if (node->getNodeType() == Node::kAttributeNode)
node = To<Attr>(node)->ownerElement();
result_collector.insert(node);
}
}
// Selector evaluation
for (Document* document : docs) {
DummyExceptionStateForTesting exception_state;
StaticElementList* element_list = document->QuerySelectorAll(
AtomicString(whitespace_trimmed_query), exception_state);
if (exception_state.HadException() || !element_list)
continue;
// Selector evaluation
for (Document* document : docs) {
DummyExceptionStateForTesting exception_state;
StaticElementList* element_list = document->QuerySelectorAll(
AtomicString(whitespace_trimmed_query), exception_state);
if (exception_state.HadException() || !element_list)
continue;
unsigned size = element_list->length();
for (unsigned i = 0; i < size; ++i)
result_collector.insert(element_list->item(i));
}
unsigned size = element_list->length();
for (unsigned i = 0; i < size; ++i)
result_collector.insert(element_list->item(i));
}
*search_id = IdentifiersFactory::CreateIdentifier();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment