Changeset 148406 in webkit


Ignore:
Timestamp:
Apr 14, 2013 12:09:59 PM (11 years ago)
Author:
akling@apple.com
Message:

Move StylePropertySet internal storage access helpers to subclass.
<http://webkit.org/b/114592>

Reviewed by Antti Koivisto.

Removed mutablePropertyVector() since most call sites are inside MutableStylePropertySet
and can access m_propertyVector directly. The few ones that aren't can just cast.

For ImmutableStylePropertySet, moved value/metadata array accessors to the subclass
and remove "immutable" from their names.

  • css/StylePropertySet.cpp:

(WebCore::StylePropertySet::immutableCopyIfNeeded):
(WebCore::ImmutableStylePropertySet::ImmutableStylePropertySet):
(WebCore::ImmutableStylePropertySet::~ImmutableStylePropertySet):
(WebCore::MutableStylePropertySet::MutableStylePropertySet):
(WebCore::MutableStylePropertySet::removeProperty):
(WebCore::MutableStylePropertySet::removePrefixedOrUnprefixedProperty):
(WebCore::MutableStylePropertySet::setProperty):
(WebCore::MutableStylePropertySet::appendPrefixingVariantProperty):
(WebCore::MutableStylePropertySet::parseDeclaration):
(WebCore::MutableStylePropertySet::addParsedProperties):
(WebCore::MutableStylePropertySet::clear):
(WebCore::MutableStylePropertySet::removePropertiesInSet):
(WebCore::MutableStylePropertySet::findCSSPropertyWithID):
(WebCore::MutableStylePropertySet::removeEquivalentProperties):
(WebCore::StylePropertySet::reportMemoryUsage):

  • css/StylePropertySet.h:

(PropertyReference):
(StylePropertySet):
(ImmutableStylePropertySet):
(WebCore::ImmutableStylePropertySet::valueArray):
(WebCore::ImmutableStylePropertySet::metadataArray):
(WebCore::StylePropertySet::PropertyReference::propertyMetadata):
(WebCore::StylePropertySet::PropertyReference::propertyValue):
(WebCore::StylePropertySet::propertyCount):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r148404 r148406  
     12013-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
    1402013-04-14  Andreas Kling  <akling@apple.com>
    241
  • trunk/Source/WebCore/css/StylePropertySet.cpp

    r148403 r148406  
    7979    if (!isMutable())
    8080        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());
    8283}
    8384
     
    9394    : StylePropertySet(cssParserMode, length)
    9495{
    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());
    9798    for (unsigned i = 0; i < length; ++i) {
    9899        metadataArray[i] = properties[i].metadata();
     
    104105ImmutableStylePropertySet::~ImmutableStylePropertySet()
    105106{
    106     CSSValue** valueArray = const_cast<CSSValue**>(immutableValueArray());
     107    CSSValue** valueArray = const_cast<CSSValue**>(this->valueArray());
    107108    for (unsigned i = 0; i < m_arraySize; ++i)
    108109        valueArray[i]->deref();
     
    113114{
    114115    if (other.isMutable())
    115         m_propertyVector = static_cast<const MutableStylePropertySet&>(other).mutablePropertyVector();
     116        m_propertyVector = static_cast<const MutableStylePropertySet&>(other).m_propertyVector;
    116117    else {
    117118        m_propertyVector.reserveInitialCapacity(other.propertyCount());
     
    627628    // A more efficient removal strategy would involve marking entries as empty
    628629    // and sweeping them when the vector grows too big.
    629     mutablePropertyVector().remove(foundPropertyIndex);
     630    m_propertyVector.remove(foundPropertyIndex);
    630631
    631632    removePrefixedOrUnprefixedProperty(propertyID);
     
    639640    if (foundPropertyIndex == -1)
    640641        return;
    641     mutablePropertyVector().remove(foundPropertyIndex);
     642    m_propertyVector.remove(foundPropertyIndex);
    642643}
    643644
     
    701702    RefPtr<CSSValue> value = prpValue;
    702703    for (unsigned i = 0; i < shorthand.length(); ++i)
    703         mutablePropertyVector().append(CSSProperty(shorthand.properties()[i], value, important));
     704        m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, important));
    704705}
    705706
     
    719720void MutableStylePropertySet::appendPrefixingVariantProperty(const CSSProperty& property)
    720721{
    721     mutablePropertyVector().append(property);
     722    m_propertyVector.append(property);
    722723    CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(property.id());
    723724    if (prefixingVariant == property.id())
    724725        return;
    725     mutablePropertyVector().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));
    726727}
    727728
     
    742743void MutableStylePropertySet::parseDeclaration(const String& styleDeclaration, StyleSheetContents* contextStyleSheet)
    743744{
    744     mutablePropertyVector().clear();
     745    m_propertyVector.clear();
    745746
    746747    CSSParserContext context(cssParserMode());
     
    755756void MutableStylePropertySet::addParsedProperties(const Vector<CSSProperty>& properties)
    756757{
    757     mutablePropertyVector().reserveCapacity(mutablePropertyVector().size() + properties.size());
     758    m_propertyVector.reserveCapacity(m_propertyVector.size() + properties.size());
    758759    for (unsigned i = 0; i < properties.size(); ++i)
    759760        addParsedProperty(properties[i]);
     
    10951096void MutableStylePropertySet::clear()
    10961097{
    1097     mutablePropertyVector().clear();
     1098    m_propertyVector.clear();
    10981099}
    10991100
     
    11121113bool MutableStylePropertySet::removePropertiesInSet(const CSSPropertyID* set, unsigned length)
    11131114{
    1114     if (mutablePropertyVector().isEmpty())
     1115    if (m_propertyVector.isEmpty())
    11151116        return false;
    11161117
     
    11211122
    11221123    Vector<CSSProperty> newProperties;
    1123     newProperties.reserveInitialCapacity(mutablePropertyVector().size());
    1124 
    1125     unsigned size = mutablePropertyVector().size();
     1124    newProperties.reserveInitialCapacity(m_propertyVector.size());
     1125
     1126    unsigned size = m_propertyVector.size();
    11261127    for (unsigned n = 0; n < size; ++n) {
    1127         const CSSProperty& property = mutablePropertyVector().at(n);
     1128        const CSSProperty& property = m_propertyVector.at(n);
    11281129        // Not quite sure if the isImportant test is needed but it matches the existing behavior.
    11291130        if (!property.isImportant()) {
     
    11341135    }
    11351136
    1136     bool changed = newProperties.size() != mutablePropertyVector().size();
    1137     mutablePropertyVector() = newProperties;
     1137    bool changed = newProperties.size() != m_propertyVector.size();
     1138    m_propertyVector = newProperties;
    11381139    return changed;
    11391140}
     
    11531154    if (foundPropertyIndex == -1)
    11541155        return 0;
    1155     return &mutablePropertyVector().at(foundPropertyIndex);
    1156 }
    1157    
     1156    return &m_propertyVector.at(foundPropertyIndex);
     1157}
     1158
    11581159bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const
    11591160{
     
    11671168{
    11681169    Vector<CSSPropertyID> propertiesToRemove;
    1169     unsigned size = mutablePropertyVector().size();
     1170    unsigned size = m_propertyVector.size();
    11701171    for (unsigned i = 0; i < size; ++i) {
    11711172        PropertyReference property = propertyAt(i);
     
    11811182{
    11821183    Vector<CSSPropertyID> propertiesToRemove;
    1183     unsigned size = mutablePropertyVector().size();
     1184    unsigned size = m_propertyVector.size();
    11841185    for (unsigned i = 0; i < size; ++i) {
    11851186        PropertyReference property = propertyAt(i);
     
    12531254    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS, actualSize);
    12541255    if (m_isMutable)
    1255         info.addMember(mutablePropertyVector(), "mutablePropertyVector()");
     1256        info.addMember(static_cast<const MutableStylePropertySet*>(this)->m_propertyVector, "m_propertyVector");
    12561257    else {
    12571258        for (unsigned i = 0; i < propertyCount(); ++i)
  • trunk/Source/WebCore/css/StylePropertySet.h

    r148404 r148406  
    7777
    7878    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;
    9281
    9382        const StylePropertySet& m_propertySet;
     
    131120    void showStyle();
    132121#endif
    133 
    134     const CSSValue** immutableValueArray() const;
    135     const StylePropertyMetadata* immutableMetadataArray() const;
    136122
    137123    bool propertyMatches(CSSPropertyID, const CSSValue*) const;
     
    153139
    154140    int findPropertyIndex(CSSPropertyID) const;
    155 
    156     Vector<CSSProperty, 4>& mutablePropertyVector();
    157     const Vector<CSSProperty, 4>& mutablePropertyVector() const;
    158141
    159142    unsigned m_cssParserMode : 2;
     
    185168    unsigned propertyCount() const { return m_arraySize; }
    186169
     170    const CSSValue** valueArray() const;
     171    const StylePropertyMetadata* metadataArray() const;
     172
    187173    void* m_storage;
    188174
     
    191177};
    192178
    193 inline const CSSValue** StylePropertySet::immutableValueArray() const
    194 {
    195     ASSERT(!m_isMutable);
     179inline const CSSValue** ImmutableStylePropertySet::valueArray() const
     180{
    196181    return reinterpret_cast<const CSSValue**>(const_cast<const void**>((&static_cast<const ImmutableStylePropertySet*>(this)->m_storage)));
    197182}
    198183
    199 inline const StylePropertyMetadata* StylePropertySet::immutableMetadataArray() const
    200 {
    201     ASSERT(!m_isMutable);
     184inline const StylePropertyMetadata* ImmutableStylePropertySet::metadataArray() const
     185{
    202186    return reinterpret_cast<const StylePropertyMetadata*>(&reinterpret_cast<const char*>((&static_cast<const ImmutableStylePropertySet*>(this)->m_storage))[m_arraySize * sizeof(CSSValue*)]);
    203187}
     
    253237};
    254238
    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;
     239inline 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
     246inline 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];
    265251}
    266252
     
    268254{
    269255    if (m_isMutable)
    270         return mutablePropertyVector().size();
     256        return static_cast<const MutableStylePropertySet*>(this)->m_propertyVector.size();
    271257    return m_arraySize;
    272258}
Note: See TracChangeset for help on using the changeset viewer.