| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All |
| 5 * rights reserved. | 5 * rights reserved. |
| 6 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 6 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 DECLARE_VIRTUAL_TRACE(); | 116 DECLARE_VIRTUAL_TRACE(); |
| 117 | 117 |
| 118 protected: | 118 protected: |
| 119 HTMLCollection(ContainerNode& base, CollectionType, ItemAfterOverrideType); | 119 HTMLCollection(ContainerNode& base, CollectionType, ItemAfterOverrideType); |
| 120 | 120 |
| 121 class NamedItemCache final : public GarbageCollected<NamedItemCache> { | 121 class NamedItemCache final : public GarbageCollected<NamedItemCache> { |
| 122 public: | 122 public: |
| 123 static NamedItemCache* create() { return new NamedItemCache; } | 123 static NamedItemCache* create() { return new NamedItemCache; } |
| 124 | 124 |
| 125 HeapVector<Member<Element>>* getElementsById(const AtomicString& id) const { | 125 const HeapVector<Member<Element>>* getElementsById( |
| 126 return m_idCache.at(id.impl()); | 126 const AtomicString& id) const { |
| 127 auto it = m_idCache.find(id.impl()); |
| 128 if (it == m_idCache.end()) |
| 129 return nullptr; |
| 130 return &it->value; |
| 127 } | 131 } |
| 128 HeapVector<Member<Element>>* getElementsByName( | 132 const HeapVector<Member<Element>>* getElementsByName( |
| 129 const AtomicString& name) const { | 133 const AtomicString& name) const { |
| 130 return m_nameCache.at(name.impl()); | 134 auto it = m_nameCache.find(name.impl()); |
| 135 if (it == m_nameCache.end()) |
| 136 return nullptr; |
| 137 return &it->value; |
| 131 } | 138 } |
| 132 void addElementWithId(const AtomicString& id, Element* element) { | 139 void addElementWithId(const AtomicString& id, Element* element) { |
| 133 addElementToMap(m_idCache, id, element); | 140 addElementToMap(m_idCache, id, element); |
| 134 } | 141 } |
| 135 void addElementWithName(const AtomicString& name, Element* element) { | 142 void addElementWithName(const AtomicString& name, Element* element) { |
| 136 addElementToMap(m_nameCache, name, element); | 143 addElementToMap(m_nameCache, name, element); |
| 137 } | 144 } |
| 138 | 145 |
| 139 DEFINE_INLINE_TRACE() { | 146 DEFINE_INLINE_TRACE() { |
| 140 visitor->trace(m_idCache); | 147 visitor->trace(m_idCache); |
| 141 visitor->trace(m_nameCache); | 148 visitor->trace(m_nameCache); |
| 142 } | 149 } |
| 143 | 150 |
| 144 private: | 151 private: |
| 145 NamedItemCache(); | 152 NamedItemCache(); |
| 146 typedef HeapHashMap<StringImpl*, Member<HeapVector<Member<Element>>>> | 153 typedef HeapHashMap<StringImpl*, HeapVector<Member<Element>>> |
| 147 StringToElementsMap; | 154 StringToElementsMap; |
| 148 static void addElementToMap(StringToElementsMap& map, | 155 static void addElementToMap(StringToElementsMap& map, |
| 149 const AtomicString& key, | 156 const AtomicString& key, |
| 150 Element* element) { | 157 Element* element) { |
| 151 Member<HeapVector<Member<Element>>>& vector = | 158 HeapVector<Member<Element>>& vector = |
| 152 map.insert(key.impl(), nullptr).storedValue->value; | 159 map.insert(key.impl(), HeapVector<Member<Element>>()) |
| 153 if (!vector) | 160 .storedValue->value; |
| 154 vector = new HeapVector<Member<Element>>; | 161 vector.push_back(element); |
| 155 vector->push_back(element); | |
| 156 } | 162 } |
| 157 | 163 |
| 158 StringToElementsMap m_idCache; | 164 StringToElementsMap m_idCache; |
| 159 StringToElementsMap m_nameCache; | 165 StringToElementsMap m_nameCache; |
| 160 }; | 166 }; |
| 161 | 167 |
| 162 bool overridesItemAfter() const { return m_overridesItemAfter; } | 168 bool overridesItemAfter() const { return m_overridesItemAfter; } |
| 163 virtual Element* virtualItemAfter(Element*) const; | 169 virtual Element* virtualItemAfter(Element*) const; |
| 164 bool shouldOnlyIncludeDirectChildren() const { | 170 bool shouldOnlyIncludeDirectChildren() const { |
| 165 return m_shouldOnlyIncludeDirectChildren; | 171 return m_shouldOnlyIncludeDirectChildren; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (!attrName || | 226 if (!attrName || |
| 221 shouldInvalidateTypeOnAttributeChange(invalidationType(), *attrName)) | 227 shouldInvalidateTypeOnAttributeChange(invalidationType(), *attrName)) |
| 222 invalidateCache(); | 228 invalidateCache(); |
| 223 else if (*attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr) | 229 else if (*attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr) |
| 224 invalidateIdNameCacheMaps(); | 230 invalidateIdNameCacheMaps(); |
| 225 } | 231 } |
| 226 | 232 |
| 227 } // namespace blink | 233 } // namespace blink |
| 228 | 234 |
| 229 #endif // HTMLCollection_h | 235 #endif // HTMLCollection_h |
| OLD | NEW |