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

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

Issue 2139843002: Allow [id=X] selectors to use the querySelector ID fast path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix assert. Created 4 years, 5 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 212d353a15db86993d98e6d39140a9c352b1789c..c739f889ace3acbb4d311a3303a70ce3cb535382 100644
--- a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
+++ b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
@@ -27,6 +27,7 @@
#include "core/dom/SelectorQuery.h"
#include "bindings/core/v8/ExceptionState.h"
+#include "core/HTMLNames.h"
#include "core/css/SelectorChecker.h"
#include "core/css/parser/CSSParser.h"
#include "core/dom/Document.h"
@@ -41,6 +42,8 @@
namespace blink {
+using namespace HTMLNames;
+
struct SingleElementSelectorQueryTrait {
typedef Element* OutputType;
static const bool shouldOnlyMatchFirstElement = true;
@@ -444,11 +447,17 @@ void SelectorDataList::executeSlowTraversingShadowTree(ContainerNode& rootNode,
}
}
-const CSSSelector* SelectorDataList::selectorForIdLookup(const CSSSelector& firstSelector) const
+static const CSSSelector* selectorForIdLookup(const CSSSelector& firstSelector)
{
for (const CSSSelector* selector = &firstSelector; selector; selector = selector->tagHistory()) {
if (selector->match() == CSSSelector::Id)
return selector;
+ // We only use the fast path when in standards mode where #id selectors
+ // are case sensitive, so we need the same behavior for [id=value].
+ if (selector->match() == CSSSelector::AttributeExact
+ && selector->attribute() == idAttr
+ && selector->attributeMatch() == CSSSelector::CaseSensitive)
+ return selector;
sashab 2016/07/12 01:37:03 Would it be worth adding a StyleResolverStats for
esprehn 2016/07/12 01:39:15 It would be worth adding some metrics, but StyleRe
if (selector->relation() != CSSSelector::SubSelector)
break;
}
@@ -473,11 +482,12 @@ void SelectorDataList::execute(ContainerNode& rootNode, typename SelectorQueryTr
}
DCHECK_EQ(m_selectors.size(), 1u);
+ DCHECK(!rootNode.document().inQuirksMode());
const CSSSelector& selector = *m_selectors[0];
const CSSSelector& firstSelector = selector;
- // Fast path for querySelector*('#id'), querySelector*('tag#id').
+ // Fast path for querySelector*('#id'), querySelector*('tag#id'), querySelector*('tag[id=example]').
if (const CSSSelector* idSelector = selectorForIdLookup(firstSelector)) {
const AtomicString& idToMatch = idSelector->value();
if (rootNode.treeScope().containsMultipleElementsWithId(idToMatch)) {
« 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