diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 3c77513be0543..c065d315b1a8f 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,22 @@ +2012-09-01 Andreas Kling + + Share inline style between cloned Nodes (copy on write.) + + + Reviewed by Antti Koivisto. + + When cloning a Node, use an immutable StylePropertySet for the new Node's inline style. + If the old Node already had an immutable inline style, we now reuse that, avoiding a copy. + Copying is deferred until mutation (either via CSSOM or setting of the style attribute.) + + * dom/ElementAttributeData.cpp: + (WebCore::ElementAttributeData::cloneDataFrom): + * css/StylePropertySet.h: + * css/StylePropertySet.cpp: + (WebCore::StylePropertySet::immutableCopyIfNeeded): + + Added. Simply returns 'this' if the object is already immutable, otherwise creates a new one. + 2012-09-01 Dirk Schulze [Qt] Fix the --minimal build after r127327 diff --git a/Source/WebCore/css/StylePropertySet.cpp b/Source/WebCore/css/StylePropertySet.cpp index a95ec1a15b943..e0d563e484321 100644 --- a/Source/WebCore/css/StylePropertySet.cpp +++ b/Source/WebCore/css/StylePropertySet.cpp @@ -61,6 +61,13 @@ PassRefPtr StylePropertySet::createImmutable(const CSSProperty return adoptRef(new (slot) StylePropertySet(properties, count, cssParserMode, /* makeMutable */ false)); } +PassRefPtr StylePropertySet::immutableCopyIfNeeded() const +{ + if (!isMutable()) + return const_cast(this); + return createImmutable(m_mutablePropertyVector->data(), m_mutablePropertyVector->size(), cssParserMode()); +} + StylePropertySet::StylePropertySet(CSSParserMode cssParserMode) : m_cssParserMode(cssParserMode) , m_ownsCSSOMWrapper(false) diff --git a/Source/WebCore/css/StylePropertySet.h b/Source/WebCore/css/StylePropertySet.h index 6ab7b8df49415..5eed32857524c 100644 --- a/Source/WebCore/css/StylePropertySet.h +++ b/Source/WebCore/css/StylePropertySet.h @@ -91,6 +91,7 @@ class StylePropertySet : public RefCounted { void addSubresourceStyleURLs(ListHashSet&, StyleSheetContents* contextStyleSheet) const; PassRefPtr copy() const; + PassRefPtr immutableCopyIfNeeded() const; void removeEquivalentProperties(const StylePropertySet*); void removeEquivalentProperties(const CSSStyleDeclaration*); diff --git a/Source/WebCore/dom/ElementAttributeData.cpp b/Source/WebCore/dom/ElementAttributeData.cpp index 3bbe82f896709..9ada92f5fcda5 100644 --- a/Source/WebCore/dom/ElementAttributeData.cpp +++ b/Source/WebCore/dom/ElementAttributeData.cpp @@ -363,7 +363,7 @@ void ElementAttributeData::cloneDataFrom(const ElementAttributeData& sourceData, } if (targetElement.isStyledElement() && sourceData.m_inlineStyleDecl) { - m_inlineStyleDecl = sourceData.m_inlineStyleDecl->copy(); + m_inlineStyleDecl = sourceData.m_inlineStyleDecl->immutableCopyIfNeeded(); targetElement.setIsStyleAttributeValid(sourceElement.isStyleAttributeValid()); } }