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

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

Issue 117313002: Simplify DocumentOrderedMap (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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 | « no previous file | Source/core/dom/DocumentOrderedMap.cpp » ('j') | Source/core/dom/DocumentOrderedMap.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/DocumentOrderedMap.h
diff --git a/Source/core/dom/DocumentOrderedMap.h b/Source/core/dom/DocumentOrderedMap.h
index b6fc8e07e0df1e0111506225fd0bc5c4bd1e0cc8..fa1e39d573fab7e50cf2331cce3541d2ea179892 100644
--- a/Source/core/dom/DocumentOrderedMap.h
+++ b/Source/core/dom/DocumentOrderedMap.h
@@ -59,23 +59,35 @@ public:
private:
template<bool keyMatches(StringImpl*, Element*)> Element* get(StringImpl*, const TreeScope*) const;
- typedef HashMap<StringImpl*, Element*> Map;
+ struct MapEntry {
+ MapEntry()
+ : element(0)
+ , count(0)
+ { }
+
+ explicit MapEntry(Element* firstElement)
+ : element(firstElement)
+ , count(1)
+ { }
+
+ Element* element;
+ unsigned count;
+ };
+
+ typedef HashMap<StringImpl*, MapEntry> Map;
- // We maintain the invariant that m_duplicateCounts is the count of all elements with a given key
- // excluding the one referenced in m_map, if any. This means it one less than the total count
- // when the first node with a given key is cached, otherwise the same as the total count.
mutable Map m_map;
- mutable HashCountedSet<StringImpl*> m_duplicateCounts;
};
inline bool DocumentOrderedMap::contains(StringImpl* id) const
{
- return m_map.contains(id) || m_duplicateCounts.contains(id);
+ return m_map.contains(id);
}
inline bool DocumentOrderedMap::containsMultiple(StringImpl* id) const
{
- return m_duplicateCounts.contains(id);
+ Map::const_iterator it = m_map.find(id);
+ return it != m_map.end() && it->value.count > 1;
}
} // namespace WebCore
« no previous file with comments | « no previous file | Source/core/dom/DocumentOrderedMap.cpp » ('j') | Source/core/dom/DocumentOrderedMap.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698