Cache style declaration CSSOM wrappers directly on MutableStylePropertySet.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Jul 2013 00:58:36 +0000 (00:58 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Jul 2013 00:58:36 +0000 (00:58 +0000)
<http://webkit.org/b/118883>

Reviewed by Gavin Barraclough

Merge https://chromium.googlesource.com/chromium/blink/+/183bcd51eb0e79cab930cf46695df05dc793630f
From Blink r153700 by <ager@chromium.org>:

In my measurements the mapping is adding more overhead than just having a field
in all MutableStylePropertySet objects. So this saves memory and makes access
faster.

* css/StylePropertySet.cpp:
(WebCore::MutableStylePropertySet::MutableStylePropertySet):
(WebCore::MutableStylePropertySet::~MutableStylePropertySet):
(WebCore::StylePropertySet::hasCSSOMWrapper):
(WebCore::MutableStylePropertySet::cssStyleDeclaration):
(WebCore::MutableStylePropertySet::ensureCSSStyleDeclaration):
(WebCore::MutableStylePropertySet::ensureInlineCSSStyleDeclaration):
* css/StylePropertySet.h:
(WebCore::StylePropertySet::StylePropertySet):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@152935 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/StylePropertySet.cpp
Source/WebCore/css/StylePropertySet.h

index 40f07f5..6196594 100644 (file)
@@ -1,3 +1,27 @@
+2013-07-19  Andreas Kling  <akling@apple.com>
+
+        Cache style declaration CSSOM wrappers directly on MutableStylePropertySet.
+        <http://webkit.org/b/118883>
+
+        Reviewed by Gavin Barraclough
+
+        Merge https://chromium.googlesource.com/chromium/blink/+/183bcd51eb0e79cab930cf46695df05dc793630f
+        From Blink r153700 by <ager@chromium.org>:
+
+        In my measurements the mapping is adding more overhead than just having a field
+        in all MutableStylePropertySet objects. So this saves memory and makes access
+        faster.
+
+        * css/StylePropertySet.cpp:
+        (WebCore::MutableStylePropertySet::MutableStylePropertySet):
+        (WebCore::MutableStylePropertySet::~MutableStylePropertySet):
+        (WebCore::StylePropertySet::hasCSSOMWrapper):
+        (WebCore::MutableStylePropertySet::cssStyleDeclaration):
+        (WebCore::MutableStylePropertySet::ensureCSSStyleDeclaration):
+        (WebCore::MutableStylePropertySet::ensureInlineCSSStyleDeclaration):
+        * css/StylePropertySet.h:
+        (WebCore::StylePropertySet::StylePropertySet):
+
 2013-07-19  Brent Fulgham  <bfulgham@apple.com>
 
         [Windows] Avoid passing addresses of temporaries to Windows API.
index c0dbffc..75785bc 100644 (file)
@@ -48,13 +48,6 @@ using namespace std;
 
 namespace WebCore {
 
-typedef HashMap<MutableStylePropertySet*, OwnPtr<PropertySetCSSStyleDeclaration> > PropertySetCSSOMWrapperMap;
-static PropertySetCSSOMWrapperMap& propertySetCSSOMWrapperMap()
-{
-    DEFINE_STATIC_LOCAL(PropertySetCSSOMWrapperMap, propertySetCSSOMWrapperMapInstance, ());
-    return propertySetCSSOMWrapperMapInstance;
-}
-
 static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count)
 {
     return sizeof(ImmutableStylePropertySet) - sizeof(void*) + sizeof(CSSValue*) * count + sizeof(StylePropertyMetadata) * count;
@@ -81,6 +74,11 @@ PassRefPtr<ImmutableStylePropertySet> StylePropertySet::immutableCopyIfNeeded()
     return ImmutableStylePropertySet::create(mutableThis->m_propertyVector.data(), mutableThis->m_propertyVector.size(), cssParserMode());
 }
 
+MutableStylePropertySet::MutableStylePropertySet(CSSParserMode cssParserMode)
+    : StylePropertySet(cssParserMode)
+{
+}
+
 MutableStylePropertySet::MutableStylePropertySet(const CSSProperty* properties, unsigned length)
     : StylePropertySet(CSSStrictMode)
 {
@@ -89,6 +87,10 @@ MutableStylePropertySet::MutableStylePropertySet(const CSSProperty* properties,
         m_propertyVector.uncheckedAppend(properties[i]);
 }
 
+MutableStylePropertySet::~MutableStylePropertySet()
+{
+}
+
 ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properties, unsigned length, CSSParserMode cssParserMode)
     : StylePropertySet(cssParserMode, length)
 {
@@ -120,13 +122,6 @@ MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other)
     }
 }
 
-MutableStylePropertySet::~MutableStylePropertySet()
-{
-    ASSERT(!m_ownsCSSOMWrapper || propertySetCSSOMWrapperMap().contains(this));
-    if (m_ownsCSSOMWrapper)
-        propertySetCSSOMWrapperMap().remove(this);
-}
-
 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const
 {
     RefPtr<CSSValue> value = getPropertyCSSValue(propertyID);
@@ -1023,6 +1018,11 @@ String StylePropertySet::asText() const
     return result.toString();
 }
 
+bool StylePropertySet::hasCSSOMWrapper() const
+{
+    return m_isMutable && static_cast<const MutableStylePropertySet*>(this)->m_cssomWrapper;
+}
+
 void MutableStylePropertySet::mergeAndOverrideOnConflict(const StylePropertySet* other)
 {
     unsigned size = other->propertyCount();
@@ -1197,34 +1197,28 @@ PassRefPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const
 
 PropertySetCSSStyleDeclaration* MutableStylePropertySet::cssStyleDeclaration()
 {
-    if (!m_ownsCSSOMWrapper)
-        return 0;
-    return propertySetCSSOMWrapperMap().get(this);
+    return m_cssomWrapper.get();
 }
 
 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration()
 {
-    if (m_ownsCSSOMWrapper) {
-        ASSERT(!static_cast<CSSStyleDeclaration*>(propertySetCSSOMWrapperMap().get(this))->parentRule());
-        ASSERT(!propertySetCSSOMWrapperMap().get(this)->parentElement());
-        return propertySetCSSOMWrapperMap().get(this);
+    if (m_cssomWrapper) {
+        ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentRule());
+        ASSERT(!m_cssomWrapper->parentElement());
+        return m_cssomWrapper.get();
     }
-    m_ownsCSSOMWrapper = true;
-    PropertySetCSSStyleDeclaration* cssomWrapper = new PropertySetCSSStyleDeclaration(this);
-    propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper));
-    return cssomWrapper;
+    m_cssomWrapper = adoptPtr(new PropertySetCSSStyleDeclaration(this));
+    return m_cssomWrapper.get();
 }
 
 CSSStyleDeclaration* MutableStylePropertySet::ensureInlineCSSStyleDeclaration(StyledElement* parentElement)
 {
-    if (m_ownsCSSOMWrapper) {
-        ASSERT(propertySetCSSOMWrapperMap().get(this)->parentElement() == parentElement);
-        return propertySetCSSOMWrapperMap().get(this);
+    if (m_cssomWrapper) {
+        ASSERT(m_cssomWrapper->parentElement() == parentElement);
+        return m_cssomWrapper.get();
     }
-    m_ownsCSSOMWrapper = true;
-    PropertySetCSSStyleDeclaration* cssomWrapper = new InlineCSSStyleDeclaration(this, parentElement);
-    propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper));
-    return cssomWrapper;
+    m_cssomWrapper = adoptPtr(new InlineCSSStyleDeclaration(this, parentElement));
+    return m_cssomWrapper.get();
 }
 
 unsigned StylePropertySet::averageSizeInBytes()
index 530169e..f453b0f 100644 (file)
@@ -107,7 +107,7 @@ public:
     String asText() const;
 
     bool isMutable() const { return m_isMutable; }
-    bool hasCSSOMWrapper() const { return m_ownsCSSOMWrapper; }
+    bool hasCSSOMWrapper() const;
 
     bool hasFailedOrCanceledSubresources() const;
 
@@ -122,14 +122,12 @@ public:
 protected:
     StylePropertySet(CSSParserMode cssParserMode)
         : m_cssParserMode(cssParserMode)
-        , m_ownsCSSOMWrapper(false)
         , m_isMutable(true)
         , m_arraySize(0)
     { }
 
     StylePropertySet(CSSParserMode cssParserMode, unsigned immutableArraySize)
         : m_cssParserMode(cssParserMode)
-        , m_ownsCSSOMWrapper(false)
         , m_isMutable(false)
         , m_arraySize(immutableArraySize)
     { }
@@ -137,9 +135,8 @@ protected:
     int findPropertyIndex(CSSPropertyID) const;
 
     unsigned m_cssParserMode : 2;
-    mutable unsigned m_ownsCSSOMWrapper : 1;
     mutable unsigned m_isMutable : 1;
-    unsigned m_arraySize : 28;
+    unsigned m_arraySize : 29;
     
 private:
     String getShorthandValue(const StylePropertyShorthand&) const;
@@ -183,12 +180,10 @@ inline const StylePropertyMetadata* ImmutableStylePropertySet::metadataArray() c
 
 class MutableStylePropertySet : public StylePropertySet {
 public:
-    ~MutableStylePropertySet();
-
     static PassRefPtr<MutableStylePropertySet> create(CSSParserMode = CSSQuirksMode);
     static PassRefPtr<MutableStylePropertySet> create(const CSSProperty* properties, unsigned count);
 
-    MutableStylePropertySet(const StylePropertySet&);
+    ~MutableStylePropertySet();
 
     unsigned propertyCount() const { return m_propertyVector.size(); }
 
@@ -228,14 +223,15 @@ public:
     Vector<CSSProperty, 4> m_propertyVector;
 
 private:
-    MutableStylePropertySet(CSSParserMode cssParserMode)
-        : StylePropertySet(cssParserMode)
-    { }
-
+    explicit MutableStylePropertySet(CSSParserMode);
+    explicit MutableStylePropertySet(const StylePropertySet&);
     MutableStylePropertySet(const CSSProperty* properties, unsigned count);
 
     bool removeShorthandProperty(CSSPropertyID);
     CSSProperty* findCSSPropertyWithID(CSSPropertyID);
+    OwnPtr<PropertySetCSSStyleDeclaration> m_cssomWrapper;
+
+    friend class StylePropertySet;
 };
 
 inline StylePropertyMetadata StylePropertySet::PropertyReference::propertyMetadata() const