Changeset 148406 in webkit
- Timestamp:
- Apr 14, 2013 12:09:59 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r148404 r148406 1 2013-04-14 Andreas Kling <akling@apple.com> 2 3 Move StylePropertySet internal storage access helpers to subclass. 4 <http://webkit.org/b/114592> 5 6 Reviewed by Antti Koivisto. 7 8 Removed mutablePropertyVector() since most call sites are inside MutableStylePropertySet 9 and can access m_propertyVector directly. The few ones that aren't can just cast. 10 11 For ImmutableStylePropertySet, moved value/metadata array accessors to the subclass 12 and remove "immutable" from their names. 13 14 * css/StylePropertySet.cpp: 15 (WebCore::StylePropertySet::immutableCopyIfNeeded): 16 (WebCore::ImmutableStylePropertySet::ImmutableStylePropertySet): 17 (WebCore::ImmutableStylePropertySet::~ImmutableStylePropertySet): 18 (WebCore::MutableStylePropertySet::MutableStylePropertySet): 19 (WebCore::MutableStylePropertySet::removeProperty): 20 (WebCore::MutableStylePropertySet::removePrefixedOrUnprefixedProperty): 21 (WebCore::MutableStylePropertySet::setProperty): 22 (WebCore::MutableStylePropertySet::appendPrefixingVariantProperty): 23 (WebCore::MutableStylePropertySet::parseDeclaration): 24 (WebCore::MutableStylePropertySet::addParsedProperties): 25 (WebCore::MutableStylePropertySet::clear): 26 (WebCore::MutableStylePropertySet::removePropertiesInSet): 27 (WebCore::MutableStylePropertySet::findCSSPropertyWithID): 28 (WebCore::MutableStylePropertySet::removeEquivalentProperties): 29 (WebCore::StylePropertySet::reportMemoryUsage): 30 * css/StylePropertySet.h: 31 (PropertyReference): 32 (StylePropertySet): 33 (ImmutableStylePropertySet): 34 (WebCore::ImmutableStylePropertySet::valueArray): 35 (WebCore::ImmutableStylePropertySet::metadataArray): 36 (WebCore::StylePropertySet::PropertyReference::propertyMetadata): 37 (WebCore::StylePropertySet::PropertyReference::propertyValue): 38 (WebCore::StylePropertySet::propertyCount): 39 1 40 2013-04-14 Andreas Kling <akling@apple.com> 2 41 -
trunk/Source/WebCore/css/StylePropertySet.cpp
r148403 r148406 79 79 if (!isMutable()) 80 80 return static_cast<ImmutableStylePropertySet*>(const_cast<StylePropertySet*>(this)); 81 return ImmutableStylePropertySet::create(mutablePropertyVector().data(), mutablePropertyVector().size(), cssParserMode()); 81 const MutableStylePropertySet* mutableThis = static_cast<const MutableStylePropertySet*>(this); 82 return ImmutableStylePropertySet::create(mutableThis->m_propertyVector.data(), mutableThis->m_propertyVector.size(), cssParserMode()); 82 83 } 83 84 … … 93 94 : StylePropertySet(cssParserMode, length) 94 95 { 95 StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>( immutableMetadataArray());96 CSSValue** valueArray = const_cast<CSSValue**>( immutableValueArray());96 StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>(this->metadataArray()); 97 CSSValue** valueArray = const_cast<CSSValue**>(this->valueArray()); 97 98 for (unsigned i = 0; i < length; ++i) { 98 99 metadataArray[i] = properties[i].metadata(); … … 104 105 ImmutableStylePropertySet::~ImmutableStylePropertySet() 105 106 { 106 CSSValue** valueArray = const_cast<CSSValue**>( immutableValueArray());107 CSSValue** valueArray = const_cast<CSSValue**>(this->valueArray()); 107 108 for (unsigned i = 0; i < m_arraySize; ++i) 108 109 valueArray[i]->deref(); … … 113 114 { 114 115 if (other.isMutable()) 115 m_propertyVector = static_cast<const MutableStylePropertySet&>(other).m utablePropertyVector();116 m_propertyVector = static_cast<const MutableStylePropertySet&>(other).m_propertyVector; 116 117 else { 117 118 m_propertyVector.reserveInitialCapacity(other.propertyCount()); … … 627 628 // A more efficient removal strategy would involve marking entries as empty 628 629 // and sweeping them when the vector grows too big. 629 m utablePropertyVector().remove(foundPropertyIndex);630 m_propertyVector.remove(foundPropertyIndex); 630 631 631 632 removePrefixedOrUnprefixedProperty(propertyID); … … 639 640 if (foundPropertyIndex == -1) 640 641 return; 641 m utablePropertyVector().remove(foundPropertyIndex);642 m_propertyVector.remove(foundPropertyIndex); 642 643 } 643 644 … … 701 702 RefPtr<CSSValue> value = prpValue; 702 703 for (unsigned i = 0; i < shorthand.length(); ++i) 703 m utablePropertyVector().append(CSSProperty(shorthand.properties()[i], value, important));704 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, important)); 704 705 } 705 706 … … 719 720 void MutableStylePropertySet::appendPrefixingVariantProperty(const CSSProperty& property) 720 721 { 721 m utablePropertyVector().append(property);722 m_propertyVector.append(property); 722 723 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(property.id()); 723 724 if (prefixingVariant == property.id()) 724 725 return; 725 m utablePropertyVector().append(CSSProperty(prefixingVariant, property.value(), property.isImportant(), property.shorthandID(), property.metadata().m_implicit));726 m_propertyVector.append(CSSProperty(prefixingVariant, property.value(), property.isImportant(), property.shorthandID(), property.metadata().m_implicit)); 726 727 } 727 728 … … 742 743 void MutableStylePropertySet::parseDeclaration(const String& styleDeclaration, StyleSheetContents* contextStyleSheet) 743 744 { 744 m utablePropertyVector().clear();745 m_propertyVector.clear(); 745 746 746 747 CSSParserContext context(cssParserMode()); … … 755 756 void MutableStylePropertySet::addParsedProperties(const Vector<CSSProperty>& properties) 756 757 { 757 m utablePropertyVector().reserveCapacity(mutablePropertyVector().size() + properties.size());758 m_propertyVector.reserveCapacity(m_propertyVector.size() + properties.size()); 758 759 for (unsigned i = 0; i < properties.size(); ++i) 759 760 addParsedProperty(properties[i]); … … 1095 1096 void MutableStylePropertySet::clear() 1096 1097 { 1097 m utablePropertyVector().clear();1098 m_propertyVector.clear(); 1098 1099 } 1099 1100 … … 1112 1113 bool MutableStylePropertySet::removePropertiesInSet(const CSSPropertyID* set, unsigned length) 1113 1114 { 1114 if (m utablePropertyVector().isEmpty())1115 if (m_propertyVector.isEmpty()) 1115 1116 return false; 1116 1117 … … 1121 1122 1122 1123 Vector<CSSProperty> newProperties; 1123 newProperties.reserveInitialCapacity(m utablePropertyVector().size());1124 1125 unsigned size = m utablePropertyVector().size();1124 newProperties.reserveInitialCapacity(m_propertyVector.size()); 1125 1126 unsigned size = m_propertyVector.size(); 1126 1127 for (unsigned n = 0; n < size; ++n) { 1127 const CSSProperty& property = m utablePropertyVector().at(n);1128 const CSSProperty& property = m_propertyVector.at(n); 1128 1129 // Not quite sure if the isImportant test is needed but it matches the existing behavior. 1129 1130 if (!property.isImportant()) { … … 1134 1135 } 1135 1136 1136 bool changed = newProperties.size() != m utablePropertyVector().size();1137 m utablePropertyVector()= newProperties;1137 bool changed = newProperties.size() != m_propertyVector.size(); 1138 m_propertyVector = newProperties; 1138 1139 return changed; 1139 1140 } … … 1153 1154 if (foundPropertyIndex == -1) 1154 1155 return 0; 1155 return &m utablePropertyVector().at(foundPropertyIndex);1156 } 1157 1156 return &m_propertyVector.at(foundPropertyIndex); 1157 } 1158 1158 1159 bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const 1159 1160 { … … 1167 1168 { 1168 1169 Vector<CSSPropertyID> propertiesToRemove; 1169 unsigned size = m utablePropertyVector().size();1170 unsigned size = m_propertyVector.size(); 1170 1171 for (unsigned i = 0; i < size; ++i) { 1171 1172 PropertyReference property = propertyAt(i); … … 1181 1182 { 1182 1183 Vector<CSSPropertyID> propertiesToRemove; 1183 unsigned size = m utablePropertyVector().size();1184 unsigned size = m_propertyVector.size(); 1184 1185 for (unsigned i = 0; i < size; ++i) { 1185 1186 PropertyReference property = propertyAt(i); … … 1253 1254 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS, actualSize); 1254 1255 if (m_isMutable) 1255 info.addMember( mutablePropertyVector(), "mutablePropertyVector()");1256 info.addMember(static_cast<const MutableStylePropertySet*>(this)->m_propertyVector, "m_propertyVector"); 1256 1257 else { 1257 1258 for (unsigned i = 0; i < propertyCount(); ++i) -
trunk/Source/WebCore/css/StylePropertySet.h
r148404 r148406 77 77 78 78 private: 79 StylePropertyMetadata propertyMetadata() const 80 { 81 if (m_propertySet.isMutable()) 82 return m_propertySet.mutablePropertyVector().at(m_index).metadata(); 83 return m_propertySet.immutableMetadataArray()[m_index]; 84 } 85 86 const CSSValue* propertyValue() const 87 { 88 if (m_propertySet.isMutable()) 89 return m_propertySet.mutablePropertyVector().at(m_index).value(); 90 return m_propertySet.immutableValueArray()[m_index]; 91 } 79 StylePropertyMetadata propertyMetadata() const; 80 const CSSValue* propertyValue() const; 92 81 93 82 const StylePropertySet& m_propertySet; … … 131 120 void showStyle(); 132 121 #endif 133 134 const CSSValue** immutableValueArray() const;135 const StylePropertyMetadata* immutableMetadataArray() const;136 122 137 123 bool propertyMatches(CSSPropertyID, const CSSValue*) const; … … 153 139 154 140 int findPropertyIndex(CSSPropertyID) const; 155 156 Vector<CSSProperty, 4>& mutablePropertyVector();157 const Vector<CSSProperty, 4>& mutablePropertyVector() const;158 141 159 142 unsigned m_cssParserMode : 2; … … 185 168 unsigned propertyCount() const { return m_arraySize; } 186 169 170 const CSSValue** valueArray() const; 171 const StylePropertyMetadata* metadataArray() const; 172 187 173 void* m_storage; 188 174 … … 191 177 }; 192 178 193 inline const CSSValue** StylePropertySet::immutableValueArray() const 194 { 195 ASSERT(!m_isMutable); 179 inline const CSSValue** ImmutableStylePropertySet::valueArray() const 180 { 196 181 return reinterpret_cast<const CSSValue**>(const_cast<const void**>((&static_cast<const ImmutableStylePropertySet*>(this)->m_storage))); 197 182 } 198 183 199 inline const StylePropertyMetadata* StylePropertySet::immutableMetadataArray() const 200 { 201 ASSERT(!m_isMutable); 184 inline const StylePropertyMetadata* ImmutableStylePropertySet::metadataArray() const 185 { 202 186 return reinterpret_cast<const StylePropertyMetadata*>(&reinterpret_cast<const char*>((&static_cast<const ImmutableStylePropertySet*>(this)->m_storage))[m_arraySize * sizeof(CSSValue*)]); 203 187 } … … 253 237 }; 254 238 255 inline Vector<CSSProperty, 4>& StylePropertySet::mutablePropertyVector() 256 { 257 ASSERT(m_isMutable); 258 return static_cast<MutableStylePropertySet*>(this)->m_propertyVector; 259 } 260 261 inline const Vector<CSSProperty, 4>& StylePropertySet::mutablePropertyVector() const 262 { 263 ASSERT(m_isMutable); 264 return static_cast<const MutableStylePropertySet*>(this)->m_propertyVector; 239 inline StylePropertyMetadata StylePropertySet::PropertyReference::propertyMetadata() const 240 { 241 if (m_propertySet.isMutable()) 242 return static_cast<const MutableStylePropertySet&>(m_propertySet).m_propertyVector.at(m_index).metadata(); 243 return static_cast<const ImmutableStylePropertySet&>(m_propertySet).metadataArray()[m_index]; 244 } 245 246 inline const CSSValue* StylePropertySet::PropertyReference::propertyValue() const 247 { 248 if (m_propertySet.isMutable()) 249 return static_cast<const MutableStylePropertySet&>(m_propertySet).m_propertyVector.at(m_index).value(); 250 return static_cast<const ImmutableStylePropertySet&>(m_propertySet).valueArray()[m_index]; 265 251 } 266 252 … … 268 254 { 269 255 if (m_isMutable) 270 return mutablePropertyVector().size();256 return static_cast<const MutableStylePropertySet*>(this)->m_propertyVector.size(); 271 257 return m_arraySize; 272 258 }
Note: See TracChangeset
for help on using the changeset viewer.