Chromium Code Reviews| 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.length()) | 73 , m_arraySize(isUnique ? 0 : other.length()) |
| 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 isEmpty(); | 111 return isEmpty(); |
| 102 | 112 |
| 103 unsigned length = this->length(); | 113 unsigned length = this->length(); |
| 104 if (length != other->length()) | 114 if (length != other->length()) |
| 105 return false; | 115 return false; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 // FIXME: Would be faster to do this comparison without calling toSt ring, which | 150 // 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 | 151 // 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. | 152 // if the attribute name has a prefix, which is rare in HTML. |
| 143 if (equalPossiblyIgnoringCase(name, attribute.name().toString(), sho uldIgnoreAttributeCase)) | 153 if (equalPossiblyIgnoringCase(name, attribute.name().toString(), sho uldIgnoreAttributeCase)) |
| 144 return i; | 154 return i; |
| 145 } | 155 } |
| 146 } | 156 } |
| 147 return kNotFound; | 157 return kNotFound; |
| 148 } | 158 } |
| 149 | 159 |
| 160 void ElementData::trace(Visitor* visitor) | |
| 161 { | |
| 162 if (m_isUnique) | |
| 163 static_cast<UniqueElementData*>(this)->traceAfterDispatch(visitor); | |
|
esprehn
2014/05/14 20:25:27
What is traceAfterDispatch? what is dispatch? Why
wibling-chromium
2014/05/15 13:15:18
This is a common pattern we use when objects don't
| |
| 164 else | |
| 165 static_cast<ShareableElementData*>(this)->traceAfterDispatch(visitor); | |
| 166 } | |
| 167 | |
| 168 void ElementData::traceAfterDispatch(Visitor* visitor) | |
| 169 { | |
| 170 visitor->trace(m_inlineStyle); | |
| 171 } | |
| 172 | |
| 150 ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes) | 173 ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes) |
| 151 : ElementData(attributes.size()) | 174 : ElementData(attributes.size()) |
| 152 { | 175 { |
| 153 for (unsigned i = 0; i < m_arraySize; ++i) | 176 for (unsigned i = 0; i < m_arraySize; ++i) |
| 154 new (&m_attributeArray[i]) Attribute(attributes[i]); | 177 new (&m_attributeArray[i]) Attribute(attributes[i]); |
| 155 } | 178 } |
| 156 | 179 |
| 157 ShareableElementData::~ShareableElementData() | 180 ShareableElementData::~ShareableElementData() |
| 158 { | 181 { |
| 159 for (unsigned i = 0; i < m_arraySize; ++i) | 182 for (unsigned i = 0; i < m_arraySize; ++i) |
| 160 m_attributeArray[i].~Attribute(); | 183 m_attributeArray[i].~Attribute(); |
| 161 } | 184 } |
| 162 | 185 |
| 163 ShareableElementData::ShareableElementData(const UniqueElementData& other) | 186 ShareableElementData::ShareableElementData(const UniqueElementData& other) |
| 164 : ElementData(other, false) | 187 : ElementData(other, false) |
| 165 { | 188 { |
| 166 ASSERT(!other.m_presentationAttributeStyle); | 189 ASSERT(!other.m_presentationAttributeStyle); |
| 167 | 190 |
| 168 if (other.m_inlineStyle) { | 191 if (other.m_inlineStyle) { |
| 169 m_inlineStyle = other.m_inlineStyle->immutableCopyIfNeeded(); | 192 m_inlineStyle = other.m_inlineStyle->immutableCopyIfNeeded(); |
| 170 } | 193 } |
| 171 | 194 |
| 172 for (unsigned i = 0; i < m_arraySize; ++i) | 195 for (unsigned i = 0; i < m_arraySize; ++i) |
| 173 new (&m_attributeArray[i]) Attribute(other.m_attributeVector.at(i)); | 196 new (&m_attributeArray[i]) Attribute(other.m_attributeVector.at(i)); |
| 174 } | 197 } |
| 175 | 198 |
| 176 PassRefPtr<ShareableElementData> ShareableElementData::createWithAttributes(cons t Vector<Attribute>& attributes) | 199 PassRefPtrWillBeRawPtr<ShareableElementData> ShareableElementData::createWithAtt ributes(const Vector<Attribute>& attributes) |
| 177 { | 200 { |
| 201 #if ENABLE(OILPAN) | |
| 202 void* slot = Heap::allocate<ElementData>(sizeForShareableElementDataWithAttr ibuteCount(attributes.size())); | |
| 203 #else | |
| 178 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(a ttributes.size())); | 204 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(a ttributes.size())); |
| 179 return adoptRef(new (slot) ShareableElementData(attributes)); | 205 #endif |
| 206 return adoptRefWillBeNoop(new (slot) ShareableElementData(attributes)); | |
| 180 } | 207 } |
| 181 | 208 |
| 182 UniqueElementData::UniqueElementData() | 209 UniqueElementData::UniqueElementData() |
| 183 { | 210 { |
| 184 } | 211 } |
| 185 | 212 |
| 186 UniqueElementData::UniqueElementData(const UniqueElementData& other) | 213 UniqueElementData::UniqueElementData(const UniqueElementData& other) |
| 187 : ElementData(other, true) | 214 : ElementData(other, true) |
| 188 , m_presentationAttributeStyle(other.m_presentationAttributeStyle) | 215 , m_presentationAttributeStyle(other.m_presentationAttributeStyle) |
| 189 , m_attributeVector(other.m_attributeVector) | 216 , m_attributeVector(other.m_attributeVector) |
| 190 { | 217 { |
| 191 m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : n ullptr; | 218 m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : n ullptr; |
| 192 } | 219 } |
| 193 | 220 |
| 194 UniqueElementData::UniqueElementData(const ShareableElementData& other) | 221 UniqueElementData::UniqueElementData(const ShareableElementData& other) |
| 195 : ElementData(other, true) | 222 : ElementData(other, true) |
| 196 { | 223 { |
| 197 // An ShareableElementData should never have a mutable inline StylePropertyS et attached. | 224 // An ShareableElementData should never have a mutable inline StylePropertyS et attached. |
| 198 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); | 225 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); |
| 199 m_inlineStyle = other.m_inlineStyle; | 226 m_inlineStyle = other.m_inlineStyle; |
| 200 | 227 |
| 201 unsigned length = other.length(); | 228 unsigned length = other.length(); |
| 202 m_attributeVector.reserveCapacity(length); | 229 m_attributeVector.reserveCapacity(length); |
| 203 for (unsigned i = 0; i < length; ++i) | 230 for (unsigned i = 0; i < length; ++i) |
| 204 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); | 231 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); |
| 205 } | 232 } |
| 206 | 233 |
| 207 PassRefPtr<UniqueElementData> UniqueElementData::create() | 234 PassRefPtrWillBeRawPtr<UniqueElementData> UniqueElementData::create() |
| 208 { | 235 { |
| 209 return adoptRef(new UniqueElementData); | 236 return adoptRefWillBeNoop(new UniqueElementData); |
| 210 } | 237 } |
| 211 | 238 |
| 212 PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const | 239 PassRefPtrWillBeRawPtr<ShareableElementData> UniqueElementData::makeShareableCop y() const |
| 213 { | 240 { |
| 241 #if ENABLE(OILPAN) | |
| 242 void* slot = Heap::allocate<ElementData>(sizeForShareableElementDataWithAttr ibuteCount(m_attributeVector.size())); | |
| 243 #else | |
| 214 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m _attributeVector.size())); | 244 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m _attributeVector.size())); |
| 215 return adoptRef(new (slot) ShareableElementData(*this)); | 245 #endif |
| 246 return adoptRefWillBeNoop(new (slot) ShareableElementData(*this)); | |
| 216 } | 247 } |
| 217 | 248 |
| 218 Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name) | 249 Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name) |
| 219 { | 250 { |
| 220 unsigned length = this->length(); | 251 unsigned length = this->length(); |
| 221 for (unsigned i = 0; i < length; ++i) { | 252 for (unsigned i = 0; i < length; ++i) { |
| 222 if (m_attributeVector.at(i).name().matches(name)) | 253 if (m_attributeVector.at(i).name().matches(name)) |
| 223 return &m_attributeVector.at(i); | 254 return &m_attributeVector.at(i); |
| 224 } | 255 } |
| 225 return 0; | 256 return 0; |
| 226 } | 257 } |
| 227 | 258 |
| 259 void UniqueElementData::traceAfterDispatch(Visitor* visitor) | |
| 260 { | |
| 261 visitor->trace(m_presentationAttributeStyle); | |
| 262 ElementData::traceAfterDispatch(visitor); | |
| 263 } | |
| 264 | |
| 228 } // namespace WebCore | 265 } // namespace WebCore |
| OLD | NEW |