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 len = length(); | 103 unsigned length = this->length(); |
104 if (len != other->length()) | 104 if (length != other->length()) |
105 return false; | 105 return false; |
106 | 106 |
107 for (unsigned i = 0; i < len; i++) { | 107 for (unsigned i = 0; i < length; ++i) { |
108 const Attribute* attribute = attributeItem(i); | 108 const Attribute* attribute = attributeItem(i); |
109 const Attribute* otherAttr = other->getAttributeItem(attribute->name()); | 109 const Attribute* otherAttr = other->getAttributeItem(attribute->name()); |
110 if (!otherAttr || attribute->value() != otherAttr->value()) | 110 if (!otherAttr || attribute->value() != otherAttr->value()) |
111 return false; | 111 return false; |
112 } | 112 } |
113 | 113 |
114 return true; | 114 return true; |
115 } | 115 } |
116 | 116 |
117 size_t ElementData::getAttrIndex(Attr* attr) const | 117 size_t ElementData::getAttrIndex(Attr* attr) const |
118 { | 118 { |
119 // This relies on the fact that Attr's QualifiedName == the Attribute's name
. | 119 // This relies on the fact that Attr's QualifiedName == the Attribute's name
. |
120 for (unsigned i = 0; i < length(); ++i) { | 120 unsigned length = this->length(); |
| 121 for (unsigned i = 0; i < length; ++i) { |
121 if (attributeItem(i)->name() == attr->qualifiedName()) | 122 if (attributeItem(i)->name() == attr->qualifiedName()) |
122 return i; | 123 return i; |
123 } | 124 } |
124 return kNotFound; | 125 return kNotFound; |
125 } | 126 } |
126 | 127 |
127 size_t ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool
shouldIgnoreAttributeCase) const | 128 size_t ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool
shouldIgnoreAttributeCase) const |
128 { | 129 { |
129 // 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: |
130 for (unsigned i = 0; i < length(); ++i) { | 131 unsigned length = this->length(); |
| 132 for (unsigned i = 0; i < length; ++i) { |
131 const Attribute* attribute = attributeItem(i); | 133 const Attribute* attribute = attributeItem(i); |
132 // FIXME: Why check the prefix? Namespace is all that should matter | 134 // FIXME: Why check the prefix? Namespace is all that should matter |
133 // and all HTML/SVG attributes have a null namespace! | 135 // and all HTML/SVG attributes have a null namespace! |
134 if (!attribute->name().hasPrefix()) { | 136 if (!attribute->name().hasPrefix()) { |
135 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, attribute->
localName())) | 137 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, attribute->
localName())) |
136 return i; | 138 return i; |
137 } else { | 139 } else { |
138 // 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 |
139 // 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 |
140 // 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. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : n
ullptr; | 191 m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : n
ullptr; |
190 } | 192 } |
191 | 193 |
192 UniqueElementData::UniqueElementData(const ShareableElementData& other) | 194 UniqueElementData::UniqueElementData(const ShareableElementData& other) |
193 : ElementData(other, true) | 195 : ElementData(other, true) |
194 { | 196 { |
195 // An ShareableElementData should never have a mutable inline StylePropertyS
et attached. | 197 // An ShareableElementData should never have a mutable inline StylePropertyS
et attached. |
196 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); | 198 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); |
197 m_inlineStyle = other.m_inlineStyle; | 199 m_inlineStyle = other.m_inlineStyle; |
198 | 200 |
199 m_attributeVector.reserveCapacity(other.length()); | 201 unsigned length = other.length(); |
200 for (unsigned i = 0; i < other.length(); ++i) | 202 m_attributeVector.reserveCapacity(length); |
| 203 for (unsigned i = 0; i < length; ++i) |
201 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); | 204 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); |
202 } | 205 } |
203 | 206 |
204 PassRefPtr<UniqueElementData> UniqueElementData::create() | 207 PassRefPtr<UniqueElementData> UniqueElementData::create() |
205 { | 208 { |
206 return adoptRef(new UniqueElementData); | 209 return adoptRef(new UniqueElementData); |
207 } | 210 } |
208 | 211 |
209 PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const | 212 PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const |
210 { | 213 { |
211 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m
_attributeVector.size())); | 214 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m
_attributeVector.size())); |
212 return adoptRef(new (slot) ShareableElementData(*this)); | 215 return adoptRef(new (slot) ShareableElementData(*this)); |
213 } | 216 } |
214 | 217 |
215 Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name) | 218 Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name) |
216 { | 219 { |
217 for (unsigned i = 0; i < length(); ++i) { | 220 unsigned length = this->length(); |
| 221 for (unsigned i = 0; i < length; ++i) { |
218 if (m_attributeVector.at(i).name().matches(name)) | 222 if (m_attributeVector.at(i).name().matches(name)) |
219 return &m_attributeVector.at(i); | 223 return &m_attributeVector.at(i); |
220 } | 224 } |
221 return 0; | 225 return 0; |
222 } | 226 } |
223 | 227 |
224 } // namespace WebCore | 228 } // namespace WebCore |
OLD | NEW |