| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2014 Apple Inc. All rights reserved. | 3 * Copyright (C) 2014 Apple Inc. All rights reserved. |
| 4 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 4 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 8 * met: | 8 * met: |
| 9 * | 9 * |
| 10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 */ | 31 */ |
| 32 | 32 |
| 33 #ifndef AttributeCollection_h | 33 #ifndef AttributeCollection_h |
| 34 #define AttributeCollection_h | 34 #define AttributeCollection_h |
| 35 | 35 |
| 36 #include "core/dom/Attr.h" | |
| 37 #include "core/dom/Attribute.h" | 36 #include "core/dom/Attribute.h" |
| 38 #include "wtf/Allocator.h" | 37 #include "wtf/Allocator.h" |
| 39 #include "wtf/Vector.h" | 38 #include "wtf/Vector.h" |
| 40 | 39 |
| 41 namespace blink { | 40 namespace blink { |
| 42 | 41 |
| 43 template <typename Container, typename ContainerMemberType = Container> | 42 template <typename Container, typename ContainerMemberType = Container> |
| 44 class AttributeCollectionGeneric { | 43 class AttributeCollectionGeneric { |
| 45 STACK_ALLOCATED(); | 44 STACK_ALLOCATED(); |
| 46 public: | 45 public: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 61 iterator begin() const { return m_attributes.data(); } | 60 iterator begin() const { return m_attributes.data(); } |
| 62 iterator end() const { return begin() + size(); } | 61 iterator end() const { return begin() + size(); } |
| 63 | 62 |
| 64 unsigned size() const { return m_attributes.size(); } | 63 unsigned size() const { return m_attributes.size(); } |
| 65 bool isEmpty() const { return !size(); } | 64 bool isEmpty() const { return !size(); } |
| 66 | 65 |
| 67 iterator find(const QualifiedName&) const; | 66 iterator find(const QualifiedName&) const; |
| 68 iterator find(const AtomicString& name, bool shouldIgnoreCase) const; | 67 iterator find(const AtomicString& name, bool shouldIgnoreCase) const; |
| 69 size_t findIndex(const QualifiedName&, bool shouldIgnoreCase = false) const; | 68 size_t findIndex(const QualifiedName&, bool shouldIgnoreCase = false) const; |
| 70 size_t findIndex(const AtomicString& name, bool shouldIgnoreCase) const; | 69 size_t findIndex(const AtomicString& name, bool shouldIgnoreCase) const; |
| 71 size_t findIndex(Attr*) const; | |
| 72 | 70 |
| 73 protected: | 71 protected: |
| 74 size_t findSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase
) const; | 72 size_t findSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase
) const; |
| 75 | 73 |
| 76 ContainerMemberType m_attributes; | 74 ContainerMemberType m_attributes; |
| 77 }; | 75 }; |
| 78 | 76 |
| 79 class AttributeArray { | 77 class AttributeArray { |
| 80 DISALLOW_NEW(); | 78 DISALLOW_NEW(); |
| 81 public: | 79 public: |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 { | 175 { |
| 178 iterator end = this->end(); | 176 iterator end = this->end(); |
| 179 for (iterator it = begin(); it != end; ++it) { | 177 for (iterator it = begin(); it != end; ++it) { |
| 180 if (it->name().matches(name)) | 178 if (it->name().matches(name)) |
| 181 return it; | 179 return it; |
| 182 } | 180 } |
| 183 return nullptr; | 181 return nullptr; |
| 184 } | 182 } |
| 185 | 183 |
| 186 template <typename Container, typename ContainerMemberType> | 184 template <typename Container, typename ContainerMemberType> |
| 187 size_t AttributeCollectionGeneric<Container, ContainerMemberType>::findIndex(Att
r* attr) const | |
| 188 { | |
| 189 // This relies on the fact that Attr's QualifiedName == the Attribute's name
. | |
| 190 iterator end = this->end(); | |
| 191 unsigned index = 0; | |
| 192 for (iterator it = begin(); it != end; ++it, ++index) { | |
| 193 if (it->name() == attr->qualifiedName()) | |
| 194 return index; | |
| 195 } | |
| 196 return kNotFound; | |
| 197 } | |
| 198 | |
| 199 template <typename Container, typename ContainerMemberType> | |
| 200 size_t AttributeCollectionGeneric<Container, ContainerMemberType>::findSlowCase(
const AtomicString& name, bool shouldIgnoreAttributeCase) const | 185 size_t AttributeCollectionGeneric<Container, ContainerMemberType>::findSlowCase(
const AtomicString& name, bool shouldIgnoreAttributeCase) const |
| 201 { | 186 { |
| 202 // Continue to checking case-insensitively and/or full namespaced names if n
ecessary: | 187 // Continue to checking case-insensitively and/or full namespaced names if n
ecessary: |
| 203 iterator end = this->end(); | 188 iterator end = this->end(); |
| 204 unsigned index = 0; | 189 unsigned index = 0; |
| 205 for (iterator it = begin(); it != end; ++it, ++index) { | 190 for (iterator it = begin(); it != end; ++it, ++index) { |
| 206 // FIXME: Why check the prefix? Namespace is all that should matter | 191 // FIXME: Why check the prefix? Namespace is all that should matter |
| 207 // and all HTML/SVG attributes have a null namespace! | 192 // and all HTML/SVG attributes have a null namespace! |
| 208 if (!it->name().hasPrefix()) { | 193 if (!it->name().hasPrefix()) { |
| 209 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, it->localNa
me())) | 194 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, it->localNa
me())) |
| 210 return index; | 195 return index; |
| 211 } else { | 196 } else { |
| 212 // FIXME: Would be faster to do this comparison without calling toSt
ring, which | 197 // FIXME: Would be faster to do this comparison without calling toSt
ring, which |
| 213 // generates a temporary string by concatenation. But this branch is
only reached | 198 // generates a temporary string by concatenation. But this branch is
only reached |
| 214 // if the attribute name has a prefix, which is rare in HTML. | 199 // if the attribute name has a prefix, which is rare in HTML. |
| 215 if (equalPossiblyIgnoringCase(name, it->name().toString(), shouldIgn
oreAttributeCase)) | 200 if (equalPossiblyIgnoringCase(name, it->name().toString(), shouldIgn
oreAttributeCase)) |
| 216 return index; | 201 return index; |
| 217 } | 202 } |
| 218 } | 203 } |
| 219 return kNotFound; | 204 return kNotFound; |
| 220 } | 205 } |
| 221 | 206 |
| 222 } // namespace blink | 207 } // namespace blink |
| 223 | 208 |
| 224 #endif // AttributeCollection_h | 209 #endif // AttributeCollection_h |
| OLD | NEW |