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 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef DocumentOrderedMap_h | 31 #ifndef DocumentOrderedMap_h |
32 #define DocumentOrderedMap_h | 32 #define DocumentOrderedMap_h |
33 | 33 |
34 #include "platform/heap/Handle.h" | 34 #include "platform/heap/Handle.h" |
35 #include "wtf/Forward.h" | 35 #include "wtf/Forward.h" |
36 #include "wtf/HashMap.h" | 36 #include "wtf/HashMap.h" |
| 37 #include "wtf/text/AtomicString.h" |
37 #include "wtf/text/StringImpl.h" | 38 #include "wtf/text/StringImpl.h" |
38 | 39 |
39 namespace blink { | 40 namespace blink { |
40 | 41 |
41 class Element; | 42 class Element; |
42 class TreeScope; | 43 class TreeScope; |
43 | 44 |
44 class DocumentOrderedMap : public NoBaseWillBeGarbageCollected<DocumentOrderedMa
p> { | 45 class DocumentOrderedMap : public NoBaseWillBeGarbageCollected<DocumentOrderedMa
p> { |
45 public: | 46 public: |
46 static PassOwnPtrWillBeRawPtr<DocumentOrderedMap> create(); | 47 static PassOwnPtrWillBeRawPtr<DocumentOrderedMap> create(); |
47 void add(StringImpl*, Element*); | 48 void add(const AtomicString&, Element*); |
48 void remove(StringImpl*, Element*); | 49 void remove(const AtomicString&, Element*); |
49 | 50 |
50 bool contains(StringImpl*) const; | 51 bool contains(const AtomicString&) const; |
51 bool containsMultiple(StringImpl*) const; | 52 bool containsMultiple(const AtomicString&) const; |
52 // concrete instantiations of the get<>() method template | 53 // concrete instantiations of the get<>() method template |
53 Element* getElementById(StringImpl*, const TreeScope*) const; | 54 Element* getElementById(const AtomicString&, const TreeScope*) const; |
54 const WillBeHeapVector<RawPtrWillBeMember<Element> >& getAllElementsById(Str
ingImpl*, const TreeScope*) const; | 55 const WillBeHeapVector<RawPtrWillBeMember<Element> >& getAllElementsById(con
st AtomicString&, const TreeScope*) const; |
55 Element* getElementByMapName(StringImpl*, const TreeScope*) const; | 56 Element* getElementByMapName(const AtomicString&, const TreeScope*) const; |
56 Element* getElementByLowercasedMapName(StringImpl*, const TreeScope*) const; | 57 Element* getElementByLowercasedMapName(const AtomicString&, const TreeScope*
) const; |
57 Element* getElementByLabelForAttribute(StringImpl*, const TreeScope*) const; | 58 Element* getElementByLabelForAttribute(const AtomicString&, const TreeScope*
) const; |
58 | 59 |
59 void trace(Visitor*); | 60 void trace(Visitor*); |
60 | 61 |
61 private: | 62 private: |
62 template<bool keyMatches(StringImpl*, Element&)> Element* get(StringImpl*, c
onst TreeScope*) const; | 63 template<bool keyMatches(const AtomicString&, const Element&)> |
| 64 Element* get(const AtomicString&, const TreeScope*) const; |
63 | 65 |
64 class MapEntry : public NoBaseWillBeGarbageCollected<MapEntry> { | 66 class MapEntry : public NoBaseWillBeGarbageCollected<MapEntry> { |
65 public: | 67 public: |
66 explicit MapEntry(Element* firstElement) | 68 explicit MapEntry(Element* firstElement) |
67 : element(firstElement) | 69 : element(firstElement) |
68 , count(1) | 70 , count(1) |
69 { | 71 { |
70 } | 72 } |
71 | 73 |
72 void trace(Visitor*); | 74 void trace(Visitor*); |
73 | 75 |
74 RawPtrWillBeMember<Element> element; | 76 RawPtrWillBeMember<Element> element; |
75 unsigned count; | 77 unsigned count; |
76 WillBeHeapVector<RawPtrWillBeMember<Element> > orderedList; | 78 WillBeHeapVector<RawPtrWillBeMember<Element> > orderedList; |
77 }; | 79 }; |
78 | 80 |
79 typedef WillBeHeapHashMap<StringImpl*, OwnPtrWillBeMember<MapEntry> > Map; | 81 typedef WillBeHeapHashMap<StringImpl*, OwnPtrWillBeMember<MapEntry> > Map; |
80 | 82 |
81 mutable Map m_map; | 83 mutable Map m_map; |
82 }; | 84 }; |
83 | 85 |
84 inline bool DocumentOrderedMap::contains(StringImpl* id) const | 86 inline bool DocumentOrderedMap::contains(const AtomicString& id) const |
85 { | 87 { |
86 return m_map.contains(id); | 88 return m_map.contains(id.impl()); |
87 } | 89 } |
88 | 90 |
89 inline bool DocumentOrderedMap::containsMultiple(StringImpl* id) const | 91 inline bool DocumentOrderedMap::containsMultiple(const AtomicString& id) const |
90 { | 92 { |
91 Map::const_iterator it = m_map.find(id); | 93 Map::const_iterator it = m_map.find(id.impl()); |
92 return it != m_map.end() && it->value->count > 1; | 94 return it != m_map.end() && it->value->count > 1; |
93 } | 95 } |
94 | 96 |
95 } // namespace blink | 97 } // namespace blink |
96 | 98 |
97 #endif // DocumentOrderedMap_h | 99 #endif // DocumentOrderedMap_h |
OLD | NEW |