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 isEmpty(); | 101 return isEmpty(); |
102 | 102 |
103 unsigned length = this->length(); | 103 AttributeIteratorAccessor attributes = attributesIterator(); |
104 if (length != other->length()) | 104 if (attributes.size() != other->length()) |
105 return false; | 105 return false; |
106 | 106 |
107 for (unsigned i = 0; i < length; ++i) { | 107 AttributeConstIterator end = attributes.end(); |
108 const Attribute& attribute = attributeItem(i); | 108 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { |
109 const Attribute* otherAttr = other->getAttributeItem(attribute.name()); | 109 const Attribute* otherAttr = other->getAttributeItem(it->name()); |
110 if (!otherAttr || attribute.value() != otherAttr->value()) | 110 if (!otherAttr || it->value() != otherAttr->value()) |
111 return false; | 111 return false; |
112 } | 112 } |
113 | |
114 return true; | 113 return true; |
115 } | 114 } |
116 | 115 |
117 size_t ElementData::getAttrIndex(Attr* attr) const | 116 size_t ElementData::getAttrIndex(Attr* attr) const |
118 { | 117 { |
119 // 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
. |
120 unsigned length = this->length(); | 119 AttributeIteratorAccessor attributes = attributesIterator(); |
121 for (unsigned i = 0; i < length; ++i) { | 120 AttributeConstIterator end = attributes.end(); |
122 if (attributeItem(i).name() == attr->qualifiedName()) | 121 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { |
123 return i; | 122 if (it->name() == attr->qualifiedName()) |
| 123 return it.index(); |
124 } | 124 } |
125 return kNotFound; | 125 return kNotFound; |
126 } | 126 } |
127 | 127 |
128 size_t ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool
shouldIgnoreAttributeCase) const | 128 size_t ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool
shouldIgnoreAttributeCase) const |
129 { | 129 { |
130 // Continue to checking case-insensitively and/or full namespaced names if n
ecessary: | 130 // Continue to checking case-insensitively and/or full namespaced names if n
ecessary: |
131 unsigned length = this->length(); | 131 AttributeIteratorAccessor attributes = attributesIterator(); |
132 for (unsigned i = 0; i < length; ++i) { | 132 AttributeConstIterator end = attributes.end(); |
133 const Attribute& attribute = attributeItem(i); | 133 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { |
134 // FIXME: Why check the prefix? Namespace is all that should matter | 134 // FIXME: Why check the prefix? Namespace is all that should matter |
135 // and all HTML/SVG attributes have a null namespace! | 135 // and all HTML/SVG attributes have a null namespace! |
136 if (!attribute.name().hasPrefix()) { | 136 if (!it->name().hasPrefix()) { |
137 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, attribute.l
ocalName())) | 137 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, it->localNa
me())) |
138 return i; | 138 return it.index(); |
139 } else { | 139 } else { |
140 // FIXME: Would be faster to do this comparison without calling toSt
ring, which | 140 // 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 | 141 // 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. | 142 // if the attribute name has a prefix, which is rare in HTML. |
143 if (equalPossiblyIgnoringCase(name, attribute.name().toString(), sho
uldIgnoreAttributeCase)) | 143 if (equalPossiblyIgnoringCase(name, it->name().toString(), shouldIgn
oreAttributeCase)) |
144 return i; | 144 return it.index(); |
145 } | 145 } |
146 } | 146 } |
147 return kNotFound; | 147 return kNotFound; |
148 } | 148 } |
149 | 149 |
150 ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes) | 150 ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes) |
151 : ElementData(attributes.size()) | 151 : ElementData(attributes.size()) |
152 { | 152 { |
153 for (unsigned i = 0; i < m_arraySize; ++i) | 153 for (unsigned i = 0; i < m_arraySize; ++i) |
154 new (&m_attributeArray[i]) Attribute(attributes[i]); | 154 new (&m_attributeArray[i]) Attribute(attributes[i]); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 210 } |
211 | 211 |
212 PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const | 212 PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const |
213 { | 213 { |
214 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m
_attributeVector.size())); | 214 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m
_attributeVector.size())); |
215 return adoptRef(new (slot) ShareableElementData(*this)); | 215 return adoptRef(new (slot) ShareableElementData(*this)); |
216 } | 216 } |
217 | 217 |
218 Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name) | 218 Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name) |
219 { | 219 { |
220 unsigned length = this->length(); | 220 unsigned length = m_attributeVector.size(); |
221 for (unsigned i = 0; i < length; ++i) { | 221 for (unsigned i = 0; i < length; ++i) { |
222 if (m_attributeVector.at(i).name().matches(name)) | 222 if (m_attributeVector.at(i).name().matches(name)) |
223 return &m_attributeVector.at(i); | 223 return &m_attributeVector.at(i); |
224 } | 224 } |
225 return 0; | 225 return 0; |
226 } | 226 } |
227 | 227 |
228 } // namespace WebCore | 228 } // namespace WebCore |
OLD | NEW |