| 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 20 matching lines...) Expand all Loading... |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/dom/ElementData.h" | 32 #include "core/dom/ElementData.h" |
| 33 | 33 |
| 34 #include "core/css/StylePropertySet.h" | 34 #include "core/css/StylePropertySet.h" |
| 35 #include "core/dom/Attr.h" | 35 #include "core/dom/Attr.h" |
| 36 #include "core/dom/QualifiedName.h" | 36 #include "core/dom/QualifiedName.h" |
| 37 #include "wtf/Vector.h" | 37 #include "wtf/Vector.h" |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| 41 struct SameSizeAsElementData : public RefCounted<SameSizeAsElementData> { | 41 struct SameSizeAsElementData : public RefCountedWillBeGarbageCollectedFinalized<
SameSizeAsElementData> { |
| 42 unsigned bitfield; | 42 unsigned bitfield; |
| 43 void* refPtrs[3]; | 43 void* pointers[3]; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 COMPILE_ASSERT(sizeof(ElementData) == sizeof(SameSizeAsElementData), element_att
ribute_data_should_stay_small); | 46 COMPILE_ASSERT(sizeof(ElementData) == sizeof(SameSizeAsElementData), element_att
ribute_data_should_stay_small); |
| 47 | 47 |
| 48 static size_t sizeForShareableElementDataWithAttributeCount(unsigned count) | 48 static size_t sizeForShareableElementDataWithAttributeCount(unsigned count) |
| 49 { | 49 { |
| 50 return sizeof(ShareableElementData) + sizeof(Attribute) * count; | 50 return sizeof(ShareableElementData) + sizeof(Attribute) * count; |
| 51 } | 51 } |
| 52 | 52 |
| 53 ElementData::ElementData() | 53 ElementData::ElementData() |
| (...skipping 19 matching lines...) Expand all Loading... |
| 73 , m_arraySize(isUnique ? 0 : other.attributeCount()) | 73 , m_arraySize(isUnique ? 0 : other.attributeCount()) |
| 74 , m_presentationAttributeStyleIsDirty(other.m_presentationAttributeStyleIsDi
rty) | 74 , m_presentationAttributeStyleIsDirty(other.m_presentationAttributeStyleIsDi
rty) |
| 75 , m_styleAttributeIsDirty(other.m_styleAttributeIsDirty) | 75 , m_styleAttributeIsDirty(other.m_styleAttributeIsDirty) |
| 76 , m_animatedSVGAttributesAreDirty(other.m_animatedSVGAttributesAreDirty) | 76 , m_animatedSVGAttributesAreDirty(other.m_animatedSVGAttributesAreDirty) |
| 77 , m_classNames(other.m_classNames) | 77 , m_classNames(other.m_classNames) |
| 78 , m_idForStyleResolution(other.m_idForStyleResolution) | 78 , m_idForStyleResolution(other.m_idForStyleResolution) |
| 79 { | 79 { |
| 80 // NOTE: The inline style is copied by the subclass copy constructor since w
e don't know what to do with it here. | 80 // NOTE: The inline style is copied by the subclass copy constructor since w
e don't know what to do with it here. |
| 81 } | 81 } |
| 82 | 82 |
| 83 #if ENABLE(OILPAN) |
| 84 void ElementData::finalizeGarbageCollectedObject() |
| 85 { |
| 86 if (m_isUnique) |
| 87 static_cast<UniqueElementData*>(this)->~UniqueElementData(); |
| 88 else |
| 89 static_cast<ShareableElementData*>(this)->~ShareableElementData(); |
| 90 } |
| 91 #else |
| 83 void ElementData::destroy() | 92 void ElementData::destroy() |
| 84 { | 93 { |
| 85 if (m_isUnique) | 94 if (m_isUnique) |
| 86 delete static_cast<UniqueElementData*>(this); | 95 delete static_cast<UniqueElementData*>(this); |
| 87 else | 96 else |
| 88 delete static_cast<ShareableElementData*>(this); | 97 delete static_cast<ShareableElementData*>(this); |
| 89 } | 98 } |
| 99 #endif |
| 90 | 100 |
| 91 PassRefPtr<UniqueElementData> ElementData::makeUniqueCopy() const | 101 PassRefPtrWillBeRawPtr<UniqueElementData> ElementData::makeUniqueCopy() const |
| 92 { | 102 { |
| 93 if (isUnique()) | 103 if (isUnique()) |
| 94 return adoptRef(new UniqueElementData(static_cast<const UniqueElementDat
a&>(*this))); | 104 return adoptRefWillBeNoop(new UniqueElementData(static_cast<const Unique
ElementData&>(*this))); |
| 95 return adoptRef(new UniqueElementData(static_cast<const ShareableElementData
&>(*this))); | 105 return adoptRefWillBeNoop(new UniqueElementData(static_cast<const ShareableE
lementData&>(*this))); |
| 96 } | 106 } |
| 97 | 107 |
| 98 bool ElementData::isEquivalent(const ElementData* other) const | 108 bool ElementData::isEquivalent(const ElementData* other) const |
| 99 { | 109 { |
| 100 if (!other) | 110 if (!other) |
| 101 return !hasAttributes(); | 111 return !hasAttributes(); |
| 102 | 112 |
| 103 AttributeCollection attributes = this->attributes(); | 113 AttributeCollection attributes = this->attributes(); |
| 104 if (attributes.size() != other->attributeCount()) | 114 if (attributes.size() != other->attributeCount()) |
| 105 return false; | 115 return false; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // FIXME: Would be faster to do this comparison without calling toSt
ring, which | 152 // FIXME: Would be faster to do this comparison without calling toSt
ring, which |
| 143 // generates a temporary string by concatenation. But this branch is
only reached | 153 // generates a temporary string by concatenation. But this branch is
only reached |
| 144 // if the attribute name has a prefix, which is rare in HTML. | 154 // if the attribute name has a prefix, which is rare in HTML. |
| 145 if (equalPossiblyIgnoringCase(name, it->name().toString(), shouldIgn
oreAttributeCase)) | 155 if (equalPossiblyIgnoringCase(name, it->name().toString(), shouldIgn
oreAttributeCase)) |
| 146 return index; | 156 return index; |
| 147 } | 157 } |
| 148 } | 158 } |
| 149 return kNotFound; | 159 return kNotFound; |
| 150 } | 160 } |
| 151 | 161 |
| 162 void ElementData::trace(Visitor* visitor) |
| 163 { |
| 164 if (m_isUnique) |
| 165 static_cast<UniqueElementData*>(this)->traceAfterDispatch(visitor); |
| 166 else |
| 167 static_cast<ShareableElementData*>(this)->traceAfterDispatch(visitor); |
| 168 } |
| 169 |
| 170 void ElementData::traceAfterDispatch(Visitor* visitor) |
| 171 { |
| 172 visitor->trace(m_inlineStyle); |
| 173 } |
| 174 |
| 152 ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes) | 175 ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes) |
| 153 : ElementData(attributes.size()) | 176 : ElementData(attributes.size()) |
| 154 { | 177 { |
| 155 for (unsigned i = 0; i < m_arraySize; ++i) | 178 for (unsigned i = 0; i < m_arraySize; ++i) |
| 156 new (&m_attributeArray[i]) Attribute(attributes[i]); | 179 new (&m_attributeArray[i]) Attribute(attributes[i]); |
| 157 } | 180 } |
| 158 | 181 |
| 159 ShareableElementData::~ShareableElementData() | 182 ShareableElementData::~ShareableElementData() |
| 160 { | 183 { |
| 161 for (unsigned i = 0; i < m_arraySize; ++i) | 184 for (unsigned i = 0; i < m_arraySize; ++i) |
| 162 m_attributeArray[i].~Attribute(); | 185 m_attributeArray[i].~Attribute(); |
| 163 } | 186 } |
| 164 | 187 |
| 165 ShareableElementData::ShareableElementData(const UniqueElementData& other) | 188 ShareableElementData::ShareableElementData(const UniqueElementData& other) |
| 166 : ElementData(other, false) | 189 : ElementData(other, false) |
| 167 { | 190 { |
| 168 ASSERT(!other.m_presentationAttributeStyle); | 191 ASSERT(!other.m_presentationAttributeStyle); |
| 169 | 192 |
| 170 if (other.m_inlineStyle) { | 193 if (other.m_inlineStyle) { |
| 171 m_inlineStyle = other.m_inlineStyle->immutableCopyIfNeeded(); | 194 m_inlineStyle = other.m_inlineStyle->immutableCopyIfNeeded(); |
| 172 } | 195 } |
| 173 | 196 |
| 174 for (unsigned i = 0; i < m_arraySize; ++i) | 197 for (unsigned i = 0; i < m_arraySize; ++i) |
| 175 new (&m_attributeArray[i]) Attribute(other.m_attributeVector.at(i)); | 198 new (&m_attributeArray[i]) Attribute(other.m_attributeVector.at(i)); |
| 176 } | 199 } |
| 177 | 200 |
| 178 PassRefPtr<ShareableElementData> ShareableElementData::createWithAttributes(cons
t Vector<Attribute>& attributes) | 201 PassRefPtrWillBeRawPtr<ShareableElementData> ShareableElementData::createWithAtt
ributes(const Vector<Attribute>& attributes) |
| 179 { | 202 { |
| 203 #if ENABLE(OILPAN) |
| 204 void* slot = Heap::allocate<ElementData>(sizeForShareableElementDataWithAttr
ibuteCount(attributes.size())); |
| 205 #else |
| 180 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(a
ttributes.size())); | 206 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(a
ttributes.size())); |
| 181 return adoptRef(new (slot) ShareableElementData(attributes)); | 207 #endif |
| 208 return adoptRefWillBeNoop(new (slot) ShareableElementData(attributes)); |
| 182 } | 209 } |
| 183 | 210 |
| 184 UniqueElementData::UniqueElementData() | 211 UniqueElementData::UniqueElementData() |
| 185 { | 212 { |
| 186 } | 213 } |
| 187 | 214 |
| 188 UniqueElementData::UniqueElementData(const UniqueElementData& other) | 215 UniqueElementData::UniqueElementData(const UniqueElementData& other) |
| 189 : ElementData(other, true) | 216 : ElementData(other, true) |
| 190 , m_presentationAttributeStyle(other.m_presentationAttributeStyle) | 217 , m_presentationAttributeStyle(other.m_presentationAttributeStyle) |
| 191 , m_attributeVector(other.m_attributeVector) | 218 , m_attributeVector(other.m_attributeVector) |
| 192 { | 219 { |
| 193 m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : n
ullptr; | 220 m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : n
ullptr; |
| 194 } | 221 } |
| 195 | 222 |
| 196 UniqueElementData::UniqueElementData(const ShareableElementData& other) | 223 UniqueElementData::UniqueElementData(const ShareableElementData& other) |
| 197 : ElementData(other, true) | 224 : ElementData(other, true) |
| 198 { | 225 { |
| 199 // An ShareableElementData should never have a mutable inline StylePropertyS
et attached. | 226 // An ShareableElementData should never have a mutable inline StylePropertyS
et attached. |
| 200 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); | 227 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); |
| 201 m_inlineStyle = other.m_inlineStyle; | 228 m_inlineStyle = other.m_inlineStyle; |
| 202 | 229 |
| 203 unsigned length = other.attributeCount(); | 230 unsigned length = other.attributeCount(); |
| 204 m_attributeVector.reserveCapacity(length); | 231 m_attributeVector.reserveCapacity(length); |
| 205 for (unsigned i = 0; i < length; ++i) | 232 for (unsigned i = 0; i < length; ++i) |
| 206 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); | 233 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); |
| 207 } | 234 } |
| 208 | 235 |
| 209 PassRefPtr<UniqueElementData> UniqueElementData::create() | 236 PassRefPtrWillBeRawPtr<UniqueElementData> UniqueElementData::create() |
| 210 { | 237 { |
| 211 return adoptRef(new UniqueElementData); | 238 return adoptRefWillBeNoop(new UniqueElementData); |
| 212 } | 239 } |
| 213 | 240 |
| 214 PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const | 241 PassRefPtrWillBeRawPtr<ShareableElementData> UniqueElementData::makeShareableCop
y() const |
| 215 { | 242 { |
| 243 #if ENABLE(OILPAN) |
| 244 void* slot = Heap::allocate<ElementData>(sizeForShareableElementDataWithAttr
ibuteCount(m_attributeVector.size())); |
| 245 #else |
| 216 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m
_attributeVector.size())); | 246 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m
_attributeVector.size())); |
| 217 return adoptRef(new (slot) ShareableElementData(*this)); | 247 #endif |
| 248 return adoptRefWillBeNoop(new (slot) ShareableElementData(*this)); |
| 218 } | 249 } |
| 219 | 250 |
| 220 Attribute* UniqueElementData::findAttributeByName(const QualifiedName& name) | 251 Attribute* UniqueElementData::findAttributeByName(const QualifiedName& name) |
| 221 { | 252 { |
| 222 unsigned length = m_attributeVector.size(); | 253 unsigned length = m_attributeVector.size(); |
| 223 for (unsigned i = 0; i < length; ++i) { | 254 for (unsigned i = 0; i < length; ++i) { |
| 224 if (m_attributeVector.at(i).name().matches(name)) | 255 if (m_attributeVector.at(i).name().matches(name)) |
| 225 return &m_attributeVector.at(i); | 256 return &m_attributeVector.at(i); |
| 226 } | 257 } |
| 227 return 0; | 258 return 0; |
| 228 } | 259 } |
| 229 | 260 |
| 261 void UniqueElementData::traceAfterDispatch(Visitor* visitor) |
| 262 { |
| 263 visitor->trace(m_presentationAttributeStyle); |
| 264 ElementData::traceAfterDispatch(visitor); |
| 265 } |
| 266 |
| 230 } // namespace WebCore | 267 } // namespace WebCore |
| OLD | NEW |