| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 if (isUnique()) | 93 if (isUnique()) |
| 94 return adoptRef(new UniqueElementData(static_cast<const UniqueElementDat
a&>(*this))); | 94 return adoptRef(new UniqueElementData(static_cast<const UniqueElementDat
a&>(*this))); |
| 95 return adoptRef(new UniqueElementData(static_cast<const ShareableElementData
&>(*this))); | 95 return adoptRef(new UniqueElementData(static_cast<const ShareableElementData
&>(*this))); |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool ElementData::isEquivalent(const ElementData* other) const | 98 bool ElementData::isEquivalent(const ElementData* other) const |
| 99 { | 99 { |
| 100 if (!other) | 100 if (!other) |
| 101 return !hasAttributes(); | 101 return !hasAttributes(); |
| 102 | 102 |
| 103 AttributeIteratorAccessor attributes = attributesIterator(); | 103 AttributeCollection attributes = this->attributes(); |
| 104 if (attributes.size() != other->attributeCount()) | 104 if (attributes.size() != other->attributeCount()) |
| 105 return false; | 105 return false; |
| 106 | 106 |
| 107 AttributeConstIterator end = attributes.end(); | 107 AttributeCollection::const_iterator end = attributes.end(); |
| 108 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { | 108 for (AttributeCollection::const_iterator it = attributes.begin(); it != end;
++it) { |
| 109 const Attribute* otherAttr = other->findAttributeByName(it->name()); | 109 const Attribute* otherAttr = other->findAttributeByName(it->name()); |
| 110 if (!otherAttr || it->value() != otherAttr->value()) | 110 if (!otherAttr || it->value() != otherAttr->value()) |
| 111 return false; | 111 return false; |
| 112 } | 112 } |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 size_t ElementData::findAttrNodeIndex(Attr* attr) const | 116 size_t ElementData::findAttrNodeIndex(Attr* attr) const |
| 117 { | 117 { |
| 118 // This relies on the fact that Attr's QualifiedName == the Attribute's name
. | 118 // This relies on the fact that Attr's QualifiedName == the Attribute's name
. |
| 119 AttributeIteratorAccessor attributes = attributesIterator(); | 119 AttributeCollection attributes = this->attributes(); |
| 120 AttributeConstIterator end = attributes.end(); | 120 AttributeCollection::const_iterator end = attributes.end(); |
| 121 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { | 121 unsigned index = 0; |
| 122 for (AttributeCollection::const_iterator it = attributes.begin(); it != end;
++it, ++index) { |
| 122 if (it->name() == attr->qualifiedName()) | 123 if (it->name() == attr->qualifiedName()) |
| 123 return it.index(); | 124 return index; |
| 124 } | 125 } |
| 125 return kNotFound; | 126 return kNotFound; |
| 126 } | 127 } |
| 127 | 128 |
| 128 size_t ElementData::findAttributeIndexByNameSlowCase(const AtomicString& name, b
ool shouldIgnoreAttributeCase) const | 129 size_t ElementData::findAttributeIndexByNameSlowCase(const AtomicString& name, b
ool shouldIgnoreAttributeCase) const |
| 129 { | 130 { |
| 130 // Continue to checking case-insensitively and/or full namespaced names if n
ecessary: | 131 // Continue to checking case-insensitively and/or full namespaced names if n
ecessary: |
| 131 AttributeIteratorAccessor attributes = attributesIterator(); | 132 AttributeCollection attributes = this->attributes(); |
| 132 AttributeConstIterator end = attributes.end(); | 133 AttributeCollection::const_iterator end = attributes.end(); |
| 133 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { | 134 unsigned index = 0; |
| 135 for (AttributeCollection::const_iterator it = attributes.begin(); it != end;
++it, ++index) { |
| 134 // FIXME: Why check the prefix? Namespace is all that should matter | 136 // FIXME: Why check the prefix? Namespace is all that should matter |
| 135 // and all HTML/SVG attributes have a null namespace! | 137 // and all HTML/SVG attributes have a null namespace! |
| 136 if (!it->name().hasPrefix()) { | 138 if (!it->name().hasPrefix()) { |
| 137 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, it->localNa
me())) | 139 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, it->localNa
me())) |
| 138 return it.index(); | 140 return index; |
| 139 } else { | 141 } else { |
| 140 // FIXME: Would be faster to do this comparison without calling toSt
ring, which | 142 // FIXME: Would be faster to do this comparison without calling toSt
ring, which |
| 141 // generates a temporary string by concatenation. But this branch is
only reached | 143 // generates a temporary string by concatenation. But this branch is
only reached |
| 142 // if the attribute name has a prefix, which is rare in HTML. | 144 // if the attribute name has a prefix, which is rare in HTML. |
| 143 if (equalPossiblyIgnoringCase(name, it->name().toString(), shouldIgn
oreAttributeCase)) | 145 if (equalPossiblyIgnoringCase(name, it->name().toString(), shouldIgn
oreAttributeCase)) |
| 144 return it.index(); | 146 return index; |
| 145 } | 147 } |
| 146 } | 148 } |
| 147 return kNotFound; | 149 return kNotFound; |
| 148 } | 150 } |
| 149 | 151 |
| 150 ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes) | 152 ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes) |
| 151 : ElementData(attributes.size()) | 153 : ElementData(attributes.size()) |
| 152 { | 154 { |
| 153 for (unsigned i = 0; i < m_arraySize; ++i) | 155 for (unsigned i = 0; i < m_arraySize; ++i) |
| 154 new (&m_attributeArray[i]) Attribute(attributes[i]); | 156 new (&m_attributeArray[i]) Attribute(attributes[i]); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 { | 221 { |
| 220 unsigned length = m_attributeVector.size(); | 222 unsigned length = m_attributeVector.size(); |
| 221 for (unsigned i = 0; i < length; ++i) { | 223 for (unsigned i = 0; i < length; ++i) { |
| 222 if (m_attributeVector.at(i).name().matches(name)) | 224 if (m_attributeVector.at(i).name().matches(name)) |
| 223 return &m_attributeVector.at(i); | 225 return &m_attributeVector.at(i); |
| 224 } | 226 } |
| 225 return 0; | 227 return 0; |
| 226 } | 228 } |
| 227 | 229 |
| 228 } // namespace WebCore | 230 } // namespace WebCore |
| OLD | NEW |