| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 bool shouldIgnoreCase) const { | 142 bool shouldIgnoreCase) const { |
| 143 iterator end = this->end(); | 143 iterator end = this->end(); |
| 144 unsigned index = 0; | 144 unsigned index = 0; |
| 145 for (iterator it = begin(); it != end; ++it, ++index) { | 145 for (iterator it = begin(); it != end; ++it, ++index) { |
| 146 if (it->name().matchesPossiblyIgnoringCase(name, shouldIgnoreCase)) | 146 if (it->name().matchesPossiblyIgnoringCase(name, shouldIgnoreCase)) |
| 147 return index; | 147 return index; |
| 148 } | 148 } |
| 149 return kNotFound; | 149 return kNotFound; |
| 150 } | 150 } |
| 151 | 151 |
| 152 // We use a boolean parameter instead of calling shouldIgnoreAttributeCase so th
at the caller | 152 // We use a boolean parameter instead of calling shouldIgnoreAttributeCase so |
| 153 // can tune the behavior (hasAttribute is case sensitive whereas getAttribute is
not). | 153 // that the caller can tune the behavior (hasAttribute is case sensitive whereas |
| 154 // getAttribute is not). |
| 154 template <typename Container, typename ContainerMemberType> | 155 template <typename Container, typename ContainerMemberType> |
| 155 inline size_t | 156 inline size_t |
| 156 AttributeCollectionGeneric<Container, ContainerMemberType>::findIndex( | 157 AttributeCollectionGeneric<Container, ContainerMemberType>::findIndex( |
| 157 const AtomicString& name, | 158 const AtomicString& name, |
| 158 bool shouldIgnoreCase) const { | 159 bool shouldIgnoreCase) const { |
| 159 bool doSlowCheck = shouldIgnoreCase; | 160 bool doSlowCheck = shouldIgnoreCase; |
| 160 | 161 |
| 161 // Optimize for the case where the attribute exists and its name exactly match
es. | 162 // Optimize for the case where the attribute exists and its name exactly |
| 163 // matches. |
| 162 iterator end = this->end(); | 164 iterator end = this->end(); |
| 163 unsigned index = 0; | 165 unsigned index = 0; |
| 164 for (iterator it = begin(); it != end; ++it, ++index) { | 166 for (iterator it = begin(); it != end; ++it, ++index) { |
| 165 // FIXME: Why check the prefix? Namespaces should be all that matter. | 167 // FIXME: Why check the prefix? Namespaces should be all that matter. |
| 166 // Most attributes (all of HTML and CSS) have no namespace. | 168 // Most attributes (all of HTML and CSS) have no namespace. |
| 167 if (!it->name().hasPrefix()) { | 169 if (!it->name().hasPrefix()) { |
| 168 if (name == it->localName()) | 170 if (name == it->localName()) |
| 169 return index; | 171 return index; |
| 170 } else { | 172 } else { |
| 171 doSlowCheck = true; | 173 doSlowCheck = true; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 187 if (it->name().matches(name)) | 189 if (it->name().matches(name)) |
| 188 return it; | 190 return it; |
| 189 } | 191 } |
| 190 return nullptr; | 192 return nullptr; |
| 191 } | 193 } |
| 192 | 194 |
| 193 template <typename Container, typename ContainerMemberType> | 195 template <typename Container, typename ContainerMemberType> |
| 194 size_t AttributeCollectionGeneric<Container, ContainerMemberType>::findSlowCase( | 196 size_t AttributeCollectionGeneric<Container, ContainerMemberType>::findSlowCase( |
| 195 const AtomicString& name, | 197 const AtomicString& name, |
| 196 bool shouldIgnoreAttributeCase) const { | 198 bool shouldIgnoreAttributeCase) const { |
| 197 // Continue to checking case-insensitively and/or full namespaced names if nec
essary: | 199 // Continue to checking case-insensitively and/or full namespaced names if |
| 200 // necessary: |
| 198 iterator end = this->end(); | 201 iterator end = this->end(); |
| 199 unsigned index = 0; | 202 unsigned index = 0; |
| 200 for (iterator it = begin(); it != end; ++it, ++index) { | 203 for (iterator it = begin(); it != end; ++it, ++index) { |
| 201 // FIXME: Why check the prefix? Namespace is all that should matter | 204 // FIXME: Why check the prefix? Namespace is all that should matter |
| 202 // and all HTML/SVG attributes have a null namespace! | 205 // and all HTML/SVG attributes have a null namespace! |
| 203 if (!it->name().hasPrefix()) { | 206 if (!it->name().hasPrefix()) { |
| 204 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, it->localName())) | 207 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, it->localName())) |
| 205 return index; | 208 return index; |
| 206 } else { | 209 } else { |
| 207 // FIXME: Would be faster to do this comparison without calling toString,
which | 210 // FIXME: Would be faster to do this comparison without calling toString, |
| 208 // generates a temporary string by concatenation. But this branch is only
reached | 211 // which generates a temporary string by concatenation. But this branch is |
| 209 // if the attribute name has a prefix, which is rare in HTML. | 212 // only reached if the attribute name has a prefix, which is rare in HTML. |
| 210 if (equalPossiblyIgnoringCase(name, it->name().toString(), | 213 if (equalPossiblyIgnoringCase(name, it->name().toString(), |
| 211 shouldIgnoreAttributeCase)) | 214 shouldIgnoreAttributeCase)) |
| 212 return index; | 215 return index; |
| 213 } | 216 } |
| 214 } | 217 } |
| 215 return kNotFound; | 218 return kNotFound; |
| 216 } | 219 } |
| 217 | 220 |
| 218 } // namespace blink | 221 } // namespace blink |
| 219 | 222 |
| 220 #endif // AttributeCollection_h | 223 #endif // AttributeCollection_h |
| OLD | NEW |