Skip to content

Commit

Permalink
Give StylePropertySet a proper mutability flag.
Browse files Browse the repository at this point in the history
<http://webkit.org/b/87675>

Reviewed by Antti Koivisto.

Add a flag to StylePropertySet that determines whether it's mutable or not. Only objects
constructed from the CSS parser (by way of StylePropertySet::adopt()) are made immutable.
This is clean-up and prep work for implementing a more efficient storage scheme for immutable
StylePropertySets (fixed-size array instead of vector) as the vast majority of them are
unlikely to ever mutate during their lifetime.

Sprinkled ASSERT(isMutable()) all over StylePropertySet to catch any attempts to modify
an immutable object.

Also made properties() const on StyleRule and friends, which brought some additional code
churn along with it.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::CSSComputedStyleDeclaration::copyPropertiesInSet):
* css/CSSFontFaceRule.cpp:
(WebCore::CSSFontFaceRule::style):
(WebCore::CSSFontFaceRule::reattach):
* css/CSSFontFaceSrcValue.cpp:
(WebCore::CSSFontFaceSrcValue::addSubresourceStyleURLs):
* css/CSSFontFaceSrcValue.h:
(CSSFontFaceSrcValue):
* css/CSSPageRule.cpp:
(WebCore::CSSPageRule::style):
(WebCore::CSSPageRule::reattach):
* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::addSubresourceStyleURLs):
* css/CSSPrimitiveValue.h:
(CSSPrimitiveValue):
* css/CSSReflectValue.cpp:
(WebCore::CSSReflectValue::addSubresourceStyleURLs):
* css/CSSReflectValue.h:
(CSSReflectValue):
* css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::style):
(WebCore::CSSStyleRule::reattach):
* css/CSSValue.cpp:
(WebCore::CSSValue::addSubresourceStyleURLs):
* css/CSSValue.h:
(CSSValue):
* css/CSSValueList.cpp:
(WebCore::CSSValueList::addSubresourceStyleURLs):
* css/CSSValueList.h:
(CSSValueList):
* css/StylePropertySet.cpp:
(WebCore::StylePropertySet::StylePropertySet):
(WebCore::StylePropertySet::setCSSParserMode):
(WebCore):
(WebCore::StylePropertySet::copyPropertiesFrom):
(WebCore::StylePropertySet::removeShorthandProperty):
(WebCore::StylePropertySet::removeProperty):
(WebCore::StylePropertySet::setProperty):
(WebCore::StylePropertySet::parseDeclaration):
(WebCore::StylePropertySet::addParsedProperties):
(WebCore::StylePropertySet::addParsedProperty):
(WebCore::StylePropertySet::merge):
(WebCore::StylePropertySet::addSubresourceStyleURLs):
(WebCore::StylePropertySet::removePropertiesInSet):
(WebCore::StylePropertySet::findPropertyWithId):
(WebCore::StylePropertySet::removeEquivalentProperties):
(WebCore::StylePropertySet::copyPropertiesInSet):
* css/StylePropertySet.h:
(WebCore::StylePropertySet::adopt):
(WebCore::StylePropertySet::adoptMutable):
(StylePropertySet):
(WebCore::StylePropertySet::isMutable):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::addMatchedProperties):
(WebCore::StyleResolver::collectMatchingRulesForList):
* css/StyleResolver.h:
(StyleResolver):
* css/StyleRule.cpp:
(WebCore::StyleRule::mutableProperties):
(WebCore):
(WebCore::StyleRulePage::mutableProperties):
(WebCore::StyleRuleFontFace::mutableProperties):
* css/StyleRule.h:
(WebCore::StyleRule::properties):
(StyleRule):
(WebCore::StyleRuleFontFace::properties):
(StyleRuleFontFace):
(WebCore::StyleRulePage::properties):
(StyleRulePage):
* dom/ElementAttributeData.cpp:
(WebCore::ElementAttributeData::ensureInlineStyle):
(WebCore::ElementAttributeData::updateInlineStyleAvoidingMutation):
* editing/EditingStyle.cpp:
(WebCore::styleFromMatchedRulesForElement):
* svg/SVGFontFaceElement.cpp:
(WebCore::SVGFontFaceElement::parseAttribute):
(WebCore::SVGFontFaceElement::rebuildFontFace):
(WebCore::SVGFontFaceElement::removedFrom):

Canonical link: https://commits.webkit.org/105503@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@118761 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Andreas Kling committed May 29, 2012
1 parent cf3ef39 commit c07c784
Show file tree
Hide file tree
Showing 24 changed files with 202 additions and 51 deletions.
99 changes: 99 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,102 @@
2012-05-29 Andreas Kling <kling@webkit.org>

Give StylePropertySet a proper mutability flag.
<http://webkit.org/b/87675>

Reviewed by Antti Koivisto.

Add a flag to StylePropertySet that determines whether it's mutable or not. Only objects
constructed from the CSS parser (by way of StylePropertySet::adopt()) are made immutable.
This is clean-up and prep work for implementing a more efficient storage scheme for immutable
StylePropertySets (fixed-size array instead of vector) as the vast majority of them are
unlikely to ever mutate during their lifetime.

Sprinkled ASSERT(isMutable()) all over StylePropertySet to catch any attempts to modify
an immutable object.

Also made properties() const on StyleRule and friends, which brought some additional code
churn along with it.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::CSSComputedStyleDeclaration::copyPropertiesInSet):
* css/CSSFontFaceRule.cpp:
(WebCore::CSSFontFaceRule::style):
(WebCore::CSSFontFaceRule::reattach):
* css/CSSFontFaceSrcValue.cpp:
(WebCore::CSSFontFaceSrcValue::addSubresourceStyleURLs):
* css/CSSFontFaceSrcValue.h:
(CSSFontFaceSrcValue):
* css/CSSPageRule.cpp:
(WebCore::CSSPageRule::style):
(WebCore::CSSPageRule::reattach):
* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::addSubresourceStyleURLs):
* css/CSSPrimitiveValue.h:
(CSSPrimitiveValue):
* css/CSSReflectValue.cpp:
(WebCore::CSSReflectValue::addSubresourceStyleURLs):
* css/CSSReflectValue.h:
(CSSReflectValue):
* css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::style):
(WebCore::CSSStyleRule::reattach):
* css/CSSValue.cpp:
(WebCore::CSSValue::addSubresourceStyleURLs):
* css/CSSValue.h:
(CSSValue):
* css/CSSValueList.cpp:
(WebCore::CSSValueList::addSubresourceStyleURLs):
* css/CSSValueList.h:
(CSSValueList):
* css/StylePropertySet.cpp:
(WebCore::StylePropertySet::StylePropertySet):
(WebCore::StylePropertySet::setCSSParserMode):
(WebCore):
(WebCore::StylePropertySet::copyPropertiesFrom):
(WebCore::StylePropertySet::removeShorthandProperty):
(WebCore::StylePropertySet::removeProperty):
(WebCore::StylePropertySet::setProperty):
(WebCore::StylePropertySet::parseDeclaration):
(WebCore::StylePropertySet::addParsedProperties):
(WebCore::StylePropertySet::addParsedProperty):
(WebCore::StylePropertySet::merge):
(WebCore::StylePropertySet::addSubresourceStyleURLs):
(WebCore::StylePropertySet::removePropertiesInSet):
(WebCore::StylePropertySet::findPropertyWithId):
(WebCore::StylePropertySet::removeEquivalentProperties):
(WebCore::StylePropertySet::copyPropertiesInSet):
* css/StylePropertySet.h:
(WebCore::StylePropertySet::adopt):
(WebCore::StylePropertySet::adoptMutable):
(StylePropertySet):
(WebCore::StylePropertySet::isMutable):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::addMatchedProperties):
(WebCore::StyleResolver::collectMatchingRulesForList):
* css/StyleResolver.h:
(StyleResolver):
* css/StyleRule.cpp:
(WebCore::StyleRule::mutableProperties):
(WebCore):
(WebCore::StyleRulePage::mutableProperties):
(WebCore::StyleRuleFontFace::mutableProperties):
* css/StyleRule.h:
(WebCore::StyleRule::properties):
(StyleRule):
(WebCore::StyleRuleFontFace::properties):
(StyleRuleFontFace):
(WebCore::StyleRulePage::properties):
(StyleRulePage):
* dom/ElementAttributeData.cpp:
(WebCore::ElementAttributeData::ensureInlineStyle):
(WebCore::ElementAttributeData::updateInlineStyleAvoidingMutation):
* editing/EditingStyle.cpp:
(WebCore::styleFromMatchedRulesForElement):
* svg/SVGFontFaceElement.cpp:
(WebCore::SVGFontFaceElement::parseAttribute):
(WebCore::SVGFontFaceElement::rebuildFontFace):
(WebCore::SVGFontFaceElement::removedFrom):

2012-05-29 Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com>

[EFL] Refactoring. Get rid of unnecessary singleCharacterString() function
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Expand Up @@ -2641,7 +2641,7 @@ PassRefPtr<StylePropertySet> CSSComputedStyleDeclaration::copyPropertiesInSet(co
if (value)
list.append(CSSProperty(set[i], value.release(), false));
}
return StylePropertySet::adopt(list);
return StylePropertySet::adoptMutable(list);
}

CSSRule* CSSComputedStyleDeclaration::parentRule() const
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/css/CSSFontFaceRule.cpp
Expand Up @@ -42,7 +42,7 @@ CSSFontFaceRule::~CSSFontFaceRule()
CSSStyleDeclaration* CSSFontFaceRule::style() const
{
if (!m_propertiesCSSOMWrapper)
m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_fontFaceRule->properties(), const_cast<CSSFontFaceRule*>(this));
m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_fontFaceRule->mutableProperties(), const_cast<CSSFontFaceRule*>(this));
return m_propertiesCSSOMWrapper.get();
}

Expand All @@ -60,7 +60,7 @@ void CSSFontFaceRule::reattach(StyleRuleFontFace* rule)
ASSERT(rule);
m_fontFaceRule = rule;
if (m_propertiesCSSOMWrapper)
m_propertiesCSSOMWrapper->reattach(m_fontFaceRule->properties());
m_propertiesCSSOMWrapper->reattach(m_fontFaceRule->mutableProperties());
}

} // namespace WebCore
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSFontFaceSrcValue.cpp
Expand Up @@ -73,7 +73,7 @@ String CSSFontFaceSrcValue::customCssText() const
return result;
}

void CSSFontFaceSrcValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet)
void CSSFontFaceSrcValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet) const
{
if (!isLocal())
addSubresourceURL(urls, styleSheet->completeURL(m_resource));
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSFontFaceSrcValue.h
Expand Up @@ -65,7 +65,7 @@ class CSSFontFaceSrcValue : public CSSValue {

String customCssText() const;

void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*);
void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*) const;

CachedFont* cachedFont(Document*);

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/css/CSSPageRule.cpp
Expand Up @@ -48,7 +48,7 @@ CSSPageRule::~CSSPageRule()
CSSStyleDeclaration* CSSPageRule::style() const
{
if (!m_propertiesCSSOMWrapper)
m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_pageRule->properties(), const_cast<CSSPageRule*>(this));
m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_pageRule->mutableProperties(), const_cast<CSSPageRule*>(this));
return m_propertiesCSSOMWrapper.get();
}

Expand Down Expand Up @@ -92,7 +92,7 @@ void CSSPageRule::reattach(StyleRulePage* rule)
ASSERT(rule);
m_pageRule = rule;
if (m_propertiesCSSOMWrapper)
m_propertiesCSSOMWrapper->reattach(m_pageRule->properties());
m_propertiesCSSOMWrapper->reattach(m_pageRule->mutableProperties());
}

} // namespace WebCore
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSPrimitiveValue.cpp
Expand Up @@ -1064,7 +1064,7 @@ String CSSPrimitiveValue::customCssText() const
return text;
}

void CSSPrimitiveValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet)
void CSSPrimitiveValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet) const
{
if (m_primitiveUnitType == CSS_URI)
addSubresourceURL(urls, styleSheet->completeURL(m_value.string));
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSPrimitiveValue.h
Expand Up @@ -283,7 +283,7 @@ class CSSPrimitiveValue : public CSSValue {

bool isQuirkValue() { return m_isQuirkValue; }

void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*);
void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*) const;

Length viewportPercentageLength();

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSReflectValue.cpp
Expand Up @@ -59,7 +59,7 @@ String CSSReflectValue::customCssText() const
return result;
}

void CSSReflectValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet)
void CSSReflectValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet) const
{
if (m_mask)
m_mask->addSubresourceStyleURLs(urls, styleSheet);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSReflectValue.h
Expand Up @@ -49,7 +49,7 @@ class CSSReflectValue : public CSSValue {

String customCssText() const;

void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*);
void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*) const;

private:
CSSReflectValue(CSSReflectionDirection direction, PassRefPtr<CSSPrimitiveValue> offset, PassRefPtr<CSSValue> mask)
Expand Down
7 changes: 4 additions & 3 deletions Source/WebCore/css/CSSStyleRule.cpp
Expand Up @@ -59,8 +59,9 @@ CSSStyleRule::~CSSStyleRule()

CSSStyleDeclaration* CSSStyleRule::style() const
{
if (!m_propertiesCSSOMWrapper)
m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_styleRule->properties(), const_cast<CSSStyleRule*>(this));
if (!m_propertiesCSSOMWrapper) {
m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_styleRule->mutableProperties(), const_cast<CSSStyleRule*>(this));
}
return m_propertiesCSSOMWrapper.get();
}

Expand Down Expand Up @@ -123,7 +124,7 @@ void CSSStyleRule::reattach(StyleRule* rule)
{
m_styleRule = rule;
if (m_propertiesCSSOMWrapper)
m_propertiesCSSOMWrapper->reattach(m_styleRule->properties());
m_propertiesCSSOMWrapper->reattach(m_styleRule->mutableProperties());
}

} // namespace WebCore
10 changes: 5 additions & 5 deletions Source/WebCore/css/CSSValue.cpp
Expand Up @@ -99,19 +99,19 @@ CSSValue::Type CSSValue::cssValueType() const
return CSS_CUSTOM;
}

void CSSValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet)
void CSSValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet) const
{
// This should get called for internal instances only.
ASSERT(!isCSSOMSafe());

if (isPrimitiveValue())
static_cast<CSSPrimitiveValue*>(this)->addSubresourceStyleURLs(urls, styleSheet);
static_cast<const CSSPrimitiveValue*>(this)->addSubresourceStyleURLs(urls, styleSheet);
else if (isValueList())
static_cast<CSSValueList*>(this)->addSubresourceStyleURLs(urls, styleSheet);
static_cast<const CSSValueList*>(this)->addSubresourceStyleURLs(urls, styleSheet);
else if (classType() == FontFaceSrcClass)
static_cast<CSSFontFaceSrcValue*>(this)->addSubresourceStyleURLs(urls, styleSheet);
static_cast<const CSSFontFaceSrcValue*>(this)->addSubresourceStyleURLs(urls, styleSheet);
else if (classType() == ReflectClass)
static_cast<CSSReflectValue*>(this)->addSubresourceStyleURLs(urls, styleSheet);
static_cast<const CSSReflectValue*>(this)->addSubresourceStyleURLs(urls, styleSheet);
}

String CSSValue::cssText() const
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSValue.h
Expand Up @@ -107,7 +107,7 @@ class CSSValue : public RefCounted<CSSValue> {

PassRefPtr<CSSValue> cloneForCSSOM() const;

void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*);
void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*) const;

protected:

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSValueList.cpp
Expand Up @@ -136,7 +136,7 @@ String CSSValueList::customCssText() const
return result.toString();
}

void CSSValueList::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet)
void CSSValueList::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet) const
{
size_t size = m_values.size();
for (size_t i = 0; i < size; ++i)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSValueList.h
Expand Up @@ -60,7 +60,7 @@ class CSSValueList : public CSSValue {

String customCssText() const;

void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*);
void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*) const;

PassRefPtr<CSSValueList> cloneForCSSOM() const;

Expand Down

0 comments on commit c07c784

Please sign in to comment.