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 26 matching lines...) Expand all Loading... |
37 #include "wtf/HashMap.h" | 37 #include "wtf/HashMap.h" |
38 #include "wtf/text/AtomicString.h" | 38 #include "wtf/text/AtomicString.h" |
39 #include "wtf/text/AtomicStringHash.h" | 39 #include "wtf/text/AtomicStringHash.h" |
40 #include "wtf/text/StringImpl.h" | 40 #include "wtf/text/StringImpl.h" |
41 | 41 |
42 namespace blink { | 42 namespace blink { |
43 | 43 |
44 class Element; | 44 class Element; |
45 class TreeScope; | 45 class TreeScope; |
46 | 46 |
47 class DocumentOrderedMap : public NoBaseWillBeGarbageCollected<DocumentOrderedMa
p> { | 47 class DocumentOrderedMap : public NoBaseWillBeGarbageCollectedFinalized<Document
OrderedMap> { |
48 USING_FAST_MALLOC_WILL_BE_REMOVED(DocumentOrderedMap); | 48 USING_FAST_MALLOC_WILL_BE_REMOVED(DocumentOrderedMap); |
49 public: | 49 public: |
50 static PassOwnPtrWillBeRawPtr<DocumentOrderedMap> create(); | 50 static PassOwnPtrWillBeRawPtr<DocumentOrderedMap> create(); |
| 51 ~DocumentOrderedMap(); |
| 52 |
51 void add(const AtomicString&, Element*); | 53 void add(const AtomicString&, Element*); |
52 void remove(const AtomicString&, Element*); | 54 void remove(const AtomicString&, Element*); |
53 | 55 |
54 bool contains(const AtomicString&) const; | 56 bool contains(const AtomicString&) const; |
55 bool containsMultiple(const AtomicString&) const; | 57 bool containsMultiple(const AtomicString&) const; |
56 // concrete instantiations of the get<>() method template | 58 // concrete instantiations of the get<>() method template |
57 Element* getElementById(const AtomicString&, const TreeScope*) const; | 59 Element* getElementById(const AtomicString&, const TreeScope*) const; |
58 const WillBeHeapVector<RawPtrWillBeMember<Element>>& getAllElementsById(cons
t AtomicString&, const TreeScope*) const; | 60 const WillBeHeapVector<RawPtrWillBeMember<Element>>& getAllElementsById(cons
t AtomicString&, const TreeScope*) const; |
59 Element* getElementByMapName(const AtomicString&, const TreeScope*) const; | 61 Element* getElementByMapName(const AtomicString&, const TreeScope*) const; |
60 Element* getElementByLowercasedMapName(const AtomicString&, const TreeScope*
) const; | 62 Element* getElementByLowercasedMapName(const AtomicString&, const TreeScope*
) const; |
61 Element* getElementByLabelForAttribute(const AtomicString&, const TreeScope*
) const; | 63 Element* getElementByLabelForAttribute(const AtomicString&, const TreeScope*
) const; |
62 | 64 |
63 DECLARE_TRACE(); | 65 DECLARE_TRACE(); |
64 | 66 |
| 67 #if ENABLE(ASSERT) |
| 68 void willRemoveId(const AtomicString&); |
| 69 #endif |
| 70 |
65 private: | 71 private: |
| 72 DocumentOrderedMap(); |
| 73 |
66 template<bool keyMatches(const AtomicString&, const Element&)> | 74 template<bool keyMatches(const AtomicString&, const Element&)> |
67 Element* get(const AtomicString&, const TreeScope*) const; | 75 Element* get(const AtomicString&, const TreeScope*) const; |
68 | 76 |
69 class MapEntry : public NoBaseWillBeGarbageCollected<MapEntry> { | 77 class MapEntry : public NoBaseWillBeGarbageCollected<MapEntry> { |
70 public: | 78 public: |
71 explicit MapEntry(Element* firstElement) | 79 explicit MapEntry(Element* firstElement) |
72 : element(firstElement) | 80 : element(firstElement) |
73 , count(1) | 81 , count(1) |
74 { | 82 { |
75 } | 83 } |
76 | 84 |
77 DECLARE_TRACE(); | 85 DECLARE_TRACE(); |
78 | 86 |
79 RawPtrWillBeMember<Element> element; | 87 RawPtrWillBeMember<Element> element; |
80 unsigned count; | 88 unsigned count; |
81 WillBeHeapVector<RawPtrWillBeMember<Element>> orderedList; | 89 WillBeHeapVector<RawPtrWillBeMember<Element>> orderedList; |
82 }; | 90 }; |
83 | 91 |
84 using Map = WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<MapEntry>>; | 92 using Map = WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<MapEntry>>; |
85 | 93 |
86 mutable Map m_map; | 94 mutable Map m_map; |
| 95 #if ENABLE(ASSERT) |
| 96 AtomicString m_removingId; |
| 97 #endif |
87 }; | 98 }; |
88 | 99 |
89 inline bool DocumentOrderedMap::contains(const AtomicString& id) const | 100 inline bool DocumentOrderedMap::contains(const AtomicString& id) const |
90 { | 101 { |
91 return m_map.contains(id); | 102 return m_map.contains(id); |
92 } | 103 } |
93 | 104 |
94 inline bool DocumentOrderedMap::containsMultiple(const AtomicString& id) const | 105 inline bool DocumentOrderedMap::containsMultiple(const AtomicString& id) const |
95 { | 106 { |
96 Map::const_iterator it = m_map.find(id); | 107 Map::const_iterator it = m_map.find(id); |
97 return it != m_map.end() && it->value->count > 1; | 108 return it != m_map.end() && it->value->count > 1; |
98 } | 109 } |
99 | 110 |
100 } // namespace blink | 111 } // namespace blink |
101 | 112 |
102 #endif // DocumentOrderedMap_h | 113 #endif // DocumentOrderedMap_h |
OLD | NEW |