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

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

Issue 22968004: Revert "Simplify DocumentOrderedMap" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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 | « no previous file | Source/core/dom/DocumentOrderedMap.cpp » ('j') | no next file with comments »
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 a86caf0e66f562a0735669e0a7104661e19f778d..b6fc8e07e0df1e0111506225fd0bc5c4bd1e0cc8 100644
--- a/Source/core/dom/DocumentOrderedMap.h
+++ b/Source/core/dom/DocumentOrderedMap.h
@@ -33,7 +33,6 @@
#include "wtf/HashCountedSet.h"
#include "wtf/HashMap.h"
-#include "wtf/Vector.h"
#include "wtf/text/StringImpl.h"
namespace WebCore {
@@ -48,60 +47,35 @@ public:
void clear();
bool contains(StringImpl*) const;
- bool containsSingle(StringImpl*) const;
bool containsMultiple(StringImpl*) const;
-
// concrete instantiations of the get<>() method template
Element* getElementById(StringImpl*, const TreeScope*) const;
- Element* getElementByName(StringImpl*, const TreeScope*) const;
Element* getElementByMapName(StringImpl*, const TreeScope*) const;
Element* getElementByLowercasedMapName(StringImpl*, const TreeScope*) const;
Element* getElementByLabelForAttribute(StringImpl*, const TreeScope*) const;
- const Vector<Element*>* getAllElementsById(StringImpl*, const TreeScope*) const;
-
void checkConsistency() const;
private:
template<bool keyMatches(StringImpl*, Element*)> Element* get(StringImpl*, const TreeScope*) const;
- struct MapEntry {
- MapEntry()
- : element(0)
- , count(0)
- {
- }
- explicit MapEntry(Element* firstElement)
- : element(firstElement)
- , count(1)
- {
- }
-
- Element* element;
- unsigned count;
- Vector<Element*> orderedList;
- };
-
- typedef HashMap<StringImpl*, MapEntry> Map;
+ typedef HashMap<StringImpl*, Element*> 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::containsSingle(StringImpl* id) const
-{
- Map::const_iterator it = m_map.find(id);
- return it != m_map.end() && it->value.count == 1;
-}
-
inline bool DocumentOrderedMap::contains(StringImpl* id) const
{
- return m_map.contains(id);
+ return m_map.contains(id) || m_duplicateCounts.contains(id);
}
inline bool DocumentOrderedMap::containsMultiple(StringImpl* id) const
{
- Map::const_iterator it = m_map.find(id);
- return it != m_map.end() && it->value.count > 1;
+ return m_duplicateCounts.contains(id);
}
} // namespace WebCore
« no previous file with comments | « no previous file | Source/core/dom/DocumentOrderedMap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698