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

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

Issue 92083002: Add fast path for tag#id selector queries (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move emptyVector Created 7 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
« no previous file with comments | « Source/core/dom/DocumentOrderedMap.h ('k') | Source/core/dom/SelectorQuery.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/DocumentOrderedMap.cpp
diff --git a/Source/core/dom/DocumentOrderedMap.cpp b/Source/core/dom/DocumentOrderedMap.cpp
index 7c7edc66a87bf198ca086b71f28a5e082d672c1c..1b1b805f9731068b41f89a369b564fe3cb553dc9 100644
--- a/Source/core/dom/DocumentOrderedMap.cpp
+++ b/Source/core/dom/DocumentOrderedMap.cpp
@@ -80,6 +80,7 @@ void DocumentOrderedMap::add(StringImpl* key, Element* element)
ASSERT(entry.count);
entry.element = 0;
entry.count++;
+ entry.orderedList.clear();
}
void DocumentOrderedMap::remove(StringImpl* key, Element* element)
@@ -97,9 +98,12 @@ void DocumentOrderedMap::remove(StringImpl* key, Element* element)
ASSERT(!entry.element || entry.element == element);
m_map.remove(it);
} else {
- if (entry.element == element)
- entry.element = 0;
+ if (entry.element == element) {
+ ASSERT(entry.orderedList.isEmpty() || entry.orderedList.first() == element);
+ entry.element = entry.orderedList.size() > 1 ? entry.orderedList[1] : 0;
+ }
entry.count--;
+ entry.orderedList.clear();
}
}
@@ -134,6 +138,34 @@ Element* DocumentOrderedMap::getElementById(StringImpl* key, const TreeScope* sc
return get<keyMatchesId>(key, scope);
}
+const Vector<Element*>& DocumentOrderedMap::getAllElementsById(StringImpl* key, const TreeScope* scope) const
+{
+ ASSERT(key);
+ ASSERT(scope);
+ DEFINE_STATIC_LOCAL(Vector<Element*>, emptyVector, ());
+
+ Map::iterator it = m_map.find(key);
+ if (it == m_map.end())
+ return emptyVector;
+
+ MapEntry& entry = it->value;
+ ASSERT(entry.count);
+
+ if (entry.orderedList.isEmpty()) {
+ entry.orderedList.reserveCapacity(entry.count);
+ for (Element* element = entry.element ? entry.element : ElementTraversal::firstWithin(*scope->rootNode()); entry.orderedList.size() < entry.count; element = ElementTraversal::next(*element)) {
+ ASSERT(element);
+ if (!keyMatchesId(key, element))
+ continue;
+ entry.orderedList.uncheckedAppend(element);
+ }
+ if (!entry.element)
+ entry.element = entry.orderedList.first();
+ }
+
+ return entry.orderedList;
+}
+
Element* DocumentOrderedMap::getElementByMapName(StringImpl* key, const TreeScope* scope) const
{
return get<keyMatchesMapName>(key, scope);
« no previous file with comments | « Source/core/dom/DocumentOrderedMap.h ('k') | Source/core/dom/SelectorQuery.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698