Changeset 127375 in webkit


Ignore:
Timestamp:
Sep 1, 2012 10:47:39 AM (12 years ago)
Author:
kling@webkit.org
Message:

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.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r127371 r127375  
     12012-09-01  Andreas Kling  <kling@webkit.org>
     2
     3        Share inline style between cloned Nodes (copy on write.)
     4        <http://webkit.org/b/95451>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        When cloning a Node, use an immutable StylePropertySet for the new Node's inline style.
     9        If the old Node already had an immutable inline style, we now reuse that, avoiding a copy.
     10        Copying is deferred until mutation (either via CSSOM or setting of the style attribute.)
     11
     12        * dom/ElementAttributeData.cpp:
     13        (WebCore::ElementAttributeData::cloneDataFrom):
     14        * css/StylePropertySet.h:
     15        * css/StylePropertySet.cpp:
     16        (WebCore::StylePropertySet::immutableCopyIfNeeded):
     17
     18            Added. Simply returns 'this' if the object is already immutable, otherwise creates a new one.
     19
    1202012-09-01  Dirk Schulze  <krit@webkit.org>
    221
  • trunk/Source/WebCore/css/StylePropertySet.cpp

    r127318 r127375  
    6060    void* slot = WTF::fastMalloc(immutableStylePropertySetSize(count));
    6161    return adoptRef(new (slot) StylePropertySet(properties, count, cssParserMode, /* makeMutable */ false));
     62}
     63
     64PassRefPtr<StylePropertySet> StylePropertySet::immutableCopyIfNeeded() const
     65{
     66    if (!isMutable())
     67        return const_cast<StylePropertySet*>(this);
     68    return createImmutable(m_mutablePropertyVector->data(), m_mutablePropertyVector->size(), cssParserMode());
    6269}
    6370
  • trunk/Source/WebCore/css/StylePropertySet.h

    r126872 r127375  
    9292
    9393    PassRefPtr<StylePropertySet> copy() const;
     94    PassRefPtr<StylePropertySet> immutableCopyIfNeeded() const;
    9495
    9596    void removeEquivalentProperties(const StylePropertySet*);
  • trunk/Source/WebCore/dom/ElementAttributeData.cpp

    r127126 r127375  
    364364
    365365    if (targetElement.isStyledElement() && sourceData.m_inlineStyleDecl) {
    366         m_inlineStyleDecl = sourceData.m_inlineStyleDecl->copy();
     366        m_inlineStyleDecl = sourceData.m_inlineStyleDecl->immutableCopyIfNeeded();
    367367        targetElement.setIsStyleAttributeValid(sourceElement.isStyleAttributeValid());
    368368    }
Note: See TracChangeset for help on using the changeset viewer.