Skip to content

Commit

Permalink
Share inline style between cloned Nodes (copy on write.)
Browse files Browse the repository at this point in the history
<http://webkit.org/b/95451>

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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127375 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Andreas Kling committed Sep 1, 2012
1 parent 0e9749a commit 2841f83
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Source/WebCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
2012-09-01 Andreas Kling <kling@webkit.org>

Share inline style between cloned Nodes (copy on write.)
<http://webkit.org/b/95451>

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 <krit@webkit.org>

[Qt] Fix the --minimal build after r127327
Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/css/StylePropertySet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ PassRefPtr<StylePropertySet> StylePropertySet::createImmutable(const CSSProperty
return adoptRef(new (slot) StylePropertySet(properties, count, cssParserMode, /* makeMutable */ false));
}

PassRefPtr<StylePropertySet> StylePropertySet::immutableCopyIfNeeded() const
{
if (!isMutable())
return const_cast<StylePropertySet*>(this);
return createImmutable(m_mutablePropertyVector->data(), m_mutablePropertyVector->size(), cssParserMode());
}

StylePropertySet::StylePropertySet(CSSParserMode cssParserMode)
: m_cssParserMode(cssParserMode)
, m_ownsCSSOMWrapper(false)
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/css/StylePropertySet.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class StylePropertySet : public RefCounted<StylePropertySet> {
void addSubresourceStyleURLs(ListHashSet<KURL>&, StyleSheetContents* contextStyleSheet) const;

PassRefPtr<StylePropertySet> copy() const;
PassRefPtr<StylePropertySet> immutableCopyIfNeeded() const;

void removeEquivalentProperties(const StylePropertySet*);
void removeEquivalentProperties(const CSSStyleDeclaration*);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/ElementAttributeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down

0 comments on commit 2841f83

Please sign in to comment.