| 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
|
|
|