OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 Element* getElementById(StringImpl*, const TreeScope*) const; | 52 Element* getElementById(StringImpl*, const TreeScope*) const; |
53 Element* getElementByMapName(StringImpl*, const TreeScope*) const; | 53 Element* getElementByMapName(StringImpl*, const TreeScope*) const; |
54 Element* getElementByLowercasedMapName(StringImpl*, const TreeScope*) const; | 54 Element* getElementByLowercasedMapName(StringImpl*, const TreeScope*) const; |
55 Element* getElementByLabelForAttribute(StringImpl*, const TreeScope*) const; | 55 Element* getElementByLabelForAttribute(StringImpl*, const TreeScope*) const; |
56 | 56 |
57 void checkConsistency() const; | 57 void checkConsistency() const; |
58 | 58 |
59 private: | 59 private: |
60 template<bool keyMatches(StringImpl*, Element*)> Element* get(StringImpl*, c
onst TreeScope*) const; | 60 template<bool keyMatches(StringImpl*, Element*)> Element* get(StringImpl*, c
onst TreeScope*) const; |
61 | 61 |
62 typedef HashMap<StringImpl*, Element*> Map; | 62 struct MapEntry { |
| 63 MapEntry() |
| 64 : element(0) |
| 65 , count(0) |
| 66 { } |
63 | 67 |
64 // We maintain the invariant that m_duplicateCounts is the count of all elem
ents with a given key | 68 explicit MapEntry(Element* firstElement) |
65 // excluding the one referenced in m_map, if any. This means it one less tha
n the total count | 69 : element(firstElement) |
66 // when the first node with a given key is cached, otherwise the same as the
total count. | 70 , count(1) |
| 71 { } |
| 72 |
| 73 Element* element; |
| 74 unsigned count; |
| 75 }; |
| 76 |
| 77 typedef HashMap<StringImpl*, MapEntry> Map; |
| 78 |
67 mutable Map m_map; | 79 mutable Map m_map; |
68 mutable HashCountedSet<StringImpl*> m_duplicateCounts; | |
69 }; | 80 }; |
70 | 81 |
71 inline bool DocumentOrderedMap::contains(StringImpl* id) const | 82 inline bool DocumentOrderedMap::contains(StringImpl* id) const |
72 { | 83 { |
73 return m_map.contains(id) || m_duplicateCounts.contains(id); | 84 return m_map.contains(id); |
74 } | 85 } |
75 | 86 |
76 inline bool DocumentOrderedMap::containsMultiple(StringImpl* id) const | 87 inline bool DocumentOrderedMap::containsMultiple(StringImpl* id) const |
77 { | 88 { |
78 return m_duplicateCounts.contains(id); | 89 Map::const_iterator it = m_map.find(id); |
| 90 return it != m_map.end() && it->value.count > 1; |
79 } | 91 } |
80 | 92 |
81 } // namespace WebCore | 93 } // namespace WebCore |
82 | 94 |
83 #endif // DocumentOrderedMap_h | 95 #endif // DocumentOrderedMap_h |
OLD | NEW |