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 NoBaseWillBeGarbageCollectedFinalized<Document OrderedMap> { | 47 class DocumentOrderedMap : public NoBaseWillBeGarbageCollected<DocumentOrderedMa p> { |
48 USING_FAST_MALLOC_WILL_BE_REMOVED(DocumentOrderedMap); | 48 USING_FAST_MALLOC_WILL_BE_REMOVED(DocumentOrderedMap); |
49 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(DocumentOrderedMap); | |
49 public: | 50 public: |
50 static PassOwnPtrWillBeRawPtr<DocumentOrderedMap> create(); | 51 static PassOwnPtrWillBeRawPtr<DocumentOrderedMap> create(); |
51 ~DocumentOrderedMap(); | |
52 | 52 |
53 void add(const AtomicString&, Element*); | 53 void add(const AtomicString&, Element*); |
54 void remove(const AtomicString&, Element*); | 54 void remove(const AtomicString&, Element*); |
55 | 55 |
56 bool contains(const AtomicString&) const; | 56 bool contains(const AtomicString&) const; |
57 bool containsMultiple(const AtomicString&) const; | 57 bool containsMultiple(const AtomicString&) const; |
58 // concrete instantiations of the get<>() method template | 58 // concrete instantiations of the get<>() method template |
59 Element* getElementById(const AtomicString&, const TreeScope*) const; | 59 Element* getElementById(const AtomicString&, const TreeScope*) const; |
60 const WillBeHeapVector<RawPtrWillBeMember<Element>>& getAllElementsById(cons t AtomicString&, const TreeScope*) const; | 60 const WillBeHeapVector<RawPtrWillBeMember<Element>>& getAllElementsById(cons t AtomicString&, const TreeScope*) const; |
61 Element* getElementByMapName(const AtomicString&, const TreeScope*) const; | 61 Element* getElementByMapName(const AtomicString&, const TreeScope*) const; |
62 Element* getElementByLowercasedMapName(const AtomicString&, const TreeScope* ) const; | 62 Element* getElementByLowercasedMapName(const AtomicString&, const TreeScope* ) const; |
63 Element* getElementByLabelForAttribute(const AtomicString&, const TreeScope* ) const; | 63 Element* getElementByLabelForAttribute(const AtomicString&, const TreeScope* ) const; |
64 | 64 |
65 DECLARE_TRACE(); | 65 DECLARE_TRACE(); |
66 | 66 |
67 #if ENABLE(ASSERT) | 67 #if ENABLE(ASSERT) |
68 void willRemoveId(const AtomicString&); | 68 void enterTreeRemoveScope(); |
esprehn
2016/01/05 07:48:33
put the class here, add an #elseif and define the
sof
2016/01/05 12:37:18
Done.
| |
69 void leaveTreeRemoveScope(); | |
69 #endif | 70 #endif |
70 | 71 |
71 private: | 72 private: |
72 DocumentOrderedMap(); | 73 DocumentOrderedMap(); |
73 | 74 |
74 template<bool keyMatches(const AtomicString&, const Element&)> | 75 template<bool keyMatches(const AtomicString&, const Element&)> |
75 Element* get(const AtomicString&, const TreeScope*) const; | 76 Element* get(const AtomicString&, const TreeScope*) const; |
76 | 77 |
77 class MapEntry : public NoBaseWillBeGarbageCollected<MapEntry> { | 78 class MapEntry : public NoBaseWillBeGarbageCollected<MapEntry> { |
78 public: | 79 public: |
79 explicit MapEntry(Element* firstElement) | 80 explicit MapEntry(Element* firstElement) |
80 : element(firstElement) | 81 : element(firstElement) |
81 , count(1) | 82 , count(1) |
82 { | 83 { |
83 } | 84 } |
84 | 85 |
85 DECLARE_TRACE(); | 86 DECLARE_TRACE(); |
86 | 87 |
87 RawPtrWillBeMember<Element> element; | 88 RawPtrWillBeMember<Element> element; |
88 unsigned count; | 89 unsigned count; |
89 WillBeHeapVector<RawPtrWillBeMember<Element>> orderedList; | 90 WillBeHeapVector<RawPtrWillBeMember<Element>> orderedList; |
90 }; | 91 }; |
91 | 92 |
92 using Map = WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<MapEntry>>; | 93 using Map = WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<MapEntry>>; |
93 | 94 |
94 mutable Map m_map; | 95 mutable Map m_map; |
95 #if ENABLE(ASSERT) | 96 #if ENABLE(ASSERT) |
96 AtomicString m_removingId; | 97 int m_treeRemovalScopeLevel = 0; |
esprehn
2016/01/05 07:48:33
I would just use a static int
sof
2016/01/05 12:37:18
Done.
| |
97 #endif | 98 #endif |
98 }; | 99 }; |
99 | 100 |
100 inline bool DocumentOrderedMap::contains(const AtomicString& id) const | 101 inline bool DocumentOrderedMap::contains(const AtomicString& id) const |
101 { | 102 { |
102 return m_map.contains(id); | 103 return m_map.contains(id); |
103 } | 104 } |
104 | 105 |
105 inline bool DocumentOrderedMap::containsMultiple(const AtomicString& id) const | 106 inline bool DocumentOrderedMap::containsMultiple(const AtomicString& id) const |
106 { | 107 { |
107 Map::const_iterator it = m_map.find(id); | 108 Map::const_iterator it = m_map.find(id); |
108 return it != m_map.end() && it->value->count > 1; | 109 return it != m_map.end() && it->value->count > 1; |
109 } | 110 } |
110 | 111 |
111 } // namespace blink | 112 } // namespace blink |
112 | 113 |
113 #endif // DocumentOrderedMap_h | 114 #endif // DocumentOrderedMap_h |
OLD | NEW |