| 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 GarbageCollected<DocumentOrderedMap> { |
| 48 USING_FAST_MALLOC_WILL_BE_REMOVED(DocumentOrderedMap); | |
| 49 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(DocumentOrderedMap); | |
| 50 public: | 48 public: |
| 51 static PassOwnPtrWillBeRawPtr<DocumentOrderedMap> create(); | 49 static RawPtr<DocumentOrderedMap> create(); |
| 52 | 50 |
| 53 void add(const AtomicString&, Element*); | 51 void add(const AtomicString&, Element*); |
| 54 void remove(const AtomicString&, Element*); | 52 void remove(const AtomicString&, Element*); |
| 55 | 53 |
| 56 bool contains(const AtomicString&) const; | 54 bool contains(const AtomicString&) const; |
| 57 bool containsMultiple(const AtomicString&) const; | 55 bool containsMultiple(const AtomicString&) const; |
| 58 // concrete instantiations of the get<>() method template | 56 // concrete instantiations of the get<>() method template |
| 59 Element* getElementById(const AtomicString&, const TreeScope*) const; | 57 Element* getElementById(const AtomicString&, const TreeScope*) const; |
| 60 const WillBeHeapVector<RawPtrWillBeMember<Element>>& getAllElementsById(cons
t AtomicString&, const TreeScope*) const; | 58 const HeapVector<Member<Element>>& getAllElementsById(const AtomicString&, c
onst TreeScope*) const; |
| 61 Element* getElementByMapName(const AtomicString&, const TreeScope*) const; | 59 Element* getElementByMapName(const AtomicString&, const TreeScope*) const; |
| 62 Element* getElementByLowercasedMapName(const AtomicString&, const TreeScope*
) const; | 60 Element* getElementByLowercasedMapName(const AtomicString&, const TreeScope*
) const; |
| 63 Element* getElementByLabelForAttribute(const AtomicString&, const TreeScope*
) const; | 61 Element* getElementByLabelForAttribute(const AtomicString&, const TreeScope*
) const; |
| 64 | 62 |
| 65 DECLARE_TRACE(); | 63 DECLARE_TRACE(); |
| 66 | 64 |
| 67 #if ENABLE(ASSERT) | 65 #if ENABLE(ASSERT) |
| 68 // While removing a ContainerNode, ID lookups won't be precise should the tr
ee | 66 // While removing a ContainerNode, ID lookups won't be precise should the tr
ee |
| 69 // have elements with duplicate IDs contained in the element being removed. | 67 // have elements with duplicate IDs contained in the element being removed. |
| 70 // Rare trees, but ID lookups may legitimately fail across such removals; | 68 // Rare trees, but ID lookups may legitimately fail across such removals; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 84 ~RemoveScope() { } | 82 ~RemoveScope() { } |
| 85 }; | 83 }; |
| 86 #endif | 84 #endif |
| 87 | 85 |
| 88 private: | 86 private: |
| 89 DocumentOrderedMap(); | 87 DocumentOrderedMap(); |
| 90 | 88 |
| 91 template<bool keyMatches(const AtomicString&, const Element&)> | 89 template<bool keyMatches(const AtomicString&, const Element&)> |
| 92 Element* get(const AtomicString&, const TreeScope*) const; | 90 Element* get(const AtomicString&, const TreeScope*) const; |
| 93 | 91 |
| 94 class MapEntry : public NoBaseWillBeGarbageCollected<MapEntry> { | 92 class MapEntry : public GarbageCollected<MapEntry> { |
| 95 public: | 93 public: |
| 96 explicit MapEntry(Element* firstElement) | 94 explicit MapEntry(Element* firstElement) |
| 97 : element(firstElement) | 95 : element(firstElement) |
| 98 , count(1) | 96 , count(1) |
| 99 { | 97 { |
| 100 } | 98 } |
| 101 | 99 |
| 102 DECLARE_TRACE(); | 100 DECLARE_TRACE(); |
| 103 | 101 |
| 104 RawPtrWillBeMember<Element> element; | 102 Member<Element> element; |
| 105 unsigned count; | 103 unsigned count; |
| 106 WillBeHeapVector<RawPtrWillBeMember<Element>> orderedList; | 104 HeapVector<Member<Element>> orderedList; |
| 107 }; | 105 }; |
| 108 | 106 |
| 109 using Map = WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<MapEntry>>; | 107 using Map = HeapHashMap<AtomicString, Member<MapEntry>>; |
| 110 | 108 |
| 111 mutable Map m_map; | 109 mutable Map m_map; |
| 112 }; | 110 }; |
| 113 | 111 |
| 114 inline bool DocumentOrderedMap::contains(const AtomicString& id) const | 112 inline bool DocumentOrderedMap::contains(const AtomicString& id) const |
| 115 { | 113 { |
| 116 return m_map.contains(id); | 114 return m_map.contains(id); |
| 117 } | 115 } |
| 118 | 116 |
| 119 inline bool DocumentOrderedMap::containsMultiple(const AtomicString& id) const | 117 inline bool DocumentOrderedMap::containsMultiple(const AtomicString& id) const |
| 120 { | 118 { |
| 121 Map::const_iterator it = m_map.find(id); | 119 Map::const_iterator it = m_map.find(id); |
| 122 return it != m_map.end() && it->value->count > 1; | 120 return it != m_map.end() && it->value->count > 1; |
| 123 } | 121 } |
| 124 | 122 |
| 125 } // namespace blink | 123 } // namespace blink |
| 126 | 124 |
| 127 #endif // DocumentOrderedMap_h | 125 #endif // DocumentOrderedMap_h |
| OLD | NEW |