Title: [106435] trunk/Source/WebCore
Revision
106435
Author
kl...@webkit.org
Date
2012-01-31 23:36:21 -0800 (Tue, 31 Jan 2012)

Log Message

Make elements that don't have attributes smaller.
<http://webkit.org/b/76876>

Reviewed by Sam Weinig and Antti Koivisto.

Move the inline style declaration from StyledElement to ElementAttributeData, since having
an inline style declaration also implies having a style attribute on the element.
This saves one CPU word per element that has no attributes.

This reduces memory consumption by 412 kB (on 64-bit) when viewing the full
HTML5 spec at <http://whatwg.org/c>.

This was rolled out once because of a performance regression which has been averted this
time around by adding an Element::ensureAttributeMap() so we can force creation of the
NamedNodeMap without also serializing the inline style for the "style" attribute.

* dom/Element.h:
(Element):
(WebCore::Element::ensureAttributeMap):
(WebCore):
* dom/ElementAttributeData.h:
(ElementAttributeData):
* dom/NamedNodeMap.cpp:
(WebCore::NamedNodeMap::ensureInlineStyleDecl):
(WebCore):
(WebCore::NamedNodeMap::destroyInlineStyleDecl):
* dom/NamedNodeMap.h:
(WebCore::NamedNodeMap::inlineStyleDecl):
(NamedNodeMap):
* dom/StyledElement.cpp:
(WebCore::StyledElement::addSubresourceAttributeURLs):
* dom/StyledElement.h:
(WebCore::StyledElement::inlineStyleDecl):
(WebCore::StyledElement::ensureInlineStyleDecl):
(StyledElement):
(WebCore::StyledElement::destroyInlineStyleDecl):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (106434 => 106435)


--- trunk/Source/WebCore/ChangeLog	2012-02-01 06:55:17 UTC (rev 106434)
+++ trunk/Source/WebCore/ChangeLog	2012-02-01 07:36:21 UTC (rev 106435)
@@ -1,3 +1,42 @@
+2012-01-31  Andreas Kling  <awesomekl...@apple.com>
+
+        Make elements that don't have attributes smaller.
+        <http://webkit.org/b/76876>
+
+        Reviewed by Sam Weinig and Antti Koivisto.
+
+        Move the inline style declaration from StyledElement to ElementAttributeData, since having
+        an inline style declaration also implies having a style attribute on the element.
+        This saves one CPU word per element that has no attributes.
+
+        This reduces memory consumption by 412 kB (on 64-bit) when viewing the full
+        HTML5 spec at <http://whatwg.org/c>.
+
+        This was rolled out once because of a performance regression which has been averted this
+        time around by adding an Element::ensureAttributeMap() so we can force creation of the
+        NamedNodeMap without also serializing the inline style for the "style" attribute.
+
+        * dom/Element.h:
+        (Element):
+        (WebCore::Element::ensureAttributeMap):
+        (WebCore):
+        * dom/ElementAttributeData.h:
+        (ElementAttributeData):
+        * dom/NamedNodeMap.cpp:
+        (WebCore::NamedNodeMap::ensureInlineStyleDecl):
+        (WebCore):
+        (WebCore::NamedNodeMap::destroyInlineStyleDecl):
+        * dom/NamedNodeMap.h:
+        (WebCore::NamedNodeMap::inlineStyleDecl):
+        (NamedNodeMap):
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::addSubresourceAttributeURLs):
+        * dom/StyledElement.h:
+        (WebCore::StyledElement::inlineStyleDecl):
+        (WebCore::StyledElement::ensureInlineStyleDecl):
+        (StyledElement):
+        (WebCore::StyledElement::destroyInlineStyleDecl):
+
 2012-01-31  Hayato Ito  <hay...@chromium.org>
 
         Add APIs, getElementsByXXX family, to ShadowRoot IDL.

Modified: trunk/Source/WebCore/dom/Element.h (106434 => 106435)


--- trunk/Source/WebCore/dom/Element.h	2012-02-01 06:55:17 UTC (rev 106434)
+++ trunk/Source/WebCore/dom/Element.h	2012-02-01 07:36:21 UTC (rev 106435)
@@ -223,6 +223,7 @@
     void parserSetAttributeMap(PassOwnPtr<NamedNodeMap>, FragmentScriptingPermission);
 
     NamedNodeMap* attributeMap() const { return m_attributeMap.get(); }
+    NamedNodeMap* ensureAttributeMap();
 
     ElementAttributeData* attributeData() const { return m_attributeMap ? m_attributeMap->attributeData() : 0; }
     ElementAttributeData* ensureAttributeData() const { return attributes()->attributeData(); }
@@ -597,6 +598,13 @@
     setAttribute(document()->idAttributeName(), value);
 }
 
+inline NamedNodeMap* Element::ensureAttributeMap()
+{
+    if (!m_attributeMap)
+        createAttributeMap();
+    return m_attributeMap.get();
+}
+
 inline Element* firstElementChild(const ContainerNode* container)
 {
     ASSERT_ARG(container, container);

Modified: trunk/Source/WebCore/dom/ElementAttributeData.h (106434 => 106435)


--- trunk/Source/WebCore/dom/ElementAttributeData.h	2012-02-01 06:55:17 UTC (rev 106434)
+++ trunk/Source/WebCore/dom/ElementAttributeData.h	2012-02-01 07:36:21 UTC (rev 106435)
@@ -26,6 +26,7 @@
 #ifndef ElementAttributeData_h
 #define ElementAttributeData_h
 
+#include "CSSMutableStyleDeclaration.h"
 #include "SpaceSplitString.h"
 
 namespace WebCore {
@@ -48,6 +49,7 @@
     {
     }
 
+    RefPtr<CSSMutableStyleDeclaration> m_inlineStyleDecl;
     SpaceSplitString m_classNames;
     AtomicString m_idForStyleResolution;
 };

Modified: trunk/Source/WebCore/dom/NamedNodeMap.cpp (106434 => 106435)


--- trunk/Source/WebCore/dom/NamedNodeMap.cpp	2012-02-01 06:55:17 UTC (rev 106434)
+++ trunk/Source/WebCore/dom/NamedNodeMap.cpp	2012-02-01 07:36:21 UTC (rev 106435)
@@ -30,6 +30,7 @@
 #include "Element.h"
 #include "ExceptionCode.h"
 #include "HTMLNames.h"
+#include "StyledElement.h"
 
 namespace WebCore {
 
@@ -320,4 +321,22 @@
     return true;
 }
 
+CSSMutableStyleDeclaration* NamedNodeMap::ensureInlineStyleDecl()
+{
+    if (!attributeData()->m_inlineStyleDecl) {
+        ASSERT(m_element->isStyledElement());
+        attributeData()->m_inlineStyleDecl = CSSMutableStyleDeclaration::createInline(static_cast<StyledElement*>(m_element));
+        attributeData()->m_inlineStyleDecl->setStrictParsing(m_element->isHTMLElement() && !m_element->document()->inQuirksMode());
+    }
+    return attributeData()->m_inlineStyleDecl.get();
+}
+
+void NamedNodeMap::destroyInlineStyleDecl()
+{
+    if (!attributeData()->m_inlineStyleDecl)
+        return;
+    attributeData()->m_inlineStyleDecl->clearParentElement();
+    attributeData()->m_inlineStyleDecl = 0;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/NamedNodeMap.h (106434 => 106435)


--- trunk/Source/WebCore/dom/NamedNodeMap.h	2012-02-01 06:55:17 UTC (rev 106434)
+++ trunk/Source/WebCore/dom/NamedNodeMap.h	2012-02-01 07:36:21 UTC (rev 106435)
@@ -99,6 +99,10 @@
     ElementAttributeData* attributeData() { return &m_attributeData; }
     const ElementAttributeData* attributeData() const { return &m_attributeData; }
 
+    CSSMutableStyleDeclaration* inlineStyleDecl() { return attributeData()->m_inlineStyleDecl.get(); }
+    CSSMutableStyleDeclaration* ensureInlineStyleDecl();
+    void destroyInlineStyleDecl();
+
 private:
     NamedNodeMap(Element* element)
         : m_element(element)

Modified: trunk/Source/WebCore/dom/StyledElement.cpp (106434 => 106435)


--- trunk/Source/WebCore/dom/StyledElement.cpp	2012-02-01 06:55:17 UTC (rev 106434)
+++ trunk/Source/WebCore/dom/StyledElement.cpp	2012-02-01 07:36:21 UTC (rev 106435)
@@ -127,21 +127,6 @@
     return Attribute::createMapped(name, value);
 }
 
-void StyledElement::createInlineStyleDecl()
-{
-    ASSERT(!m_inlineStyleDecl);
-    m_inlineStyleDecl = CSSMutableStyleDeclaration::createInline(this);
-    m_inlineStyleDecl->setStrictParsing(isHTMLElement() && !document()->inQuirksMode());
-}
-
-void StyledElement::destroyInlineStyleDecl()
-{
-    if (!m_inlineStyleDecl)
-        return;
-    m_inlineStyleDecl->clearParentElement();
-    m_inlineStyleDecl = 0;
-}
-
 void StyledElement::attributeChanged(Attribute* attr, bool preserveDecls)
 {
     if (attr->name() == HTMLNames::nameAttr)
@@ -241,18 +226,6 @@
     }
 }
 
-CSSMutableStyleDeclaration* StyledElement::ensureInlineStyleDecl()
-{
-    if (!m_inlineStyleDecl)
-        createInlineStyleDecl();
-    return m_inlineStyleDecl.get();
-}
-
-CSSStyleDeclaration* StyledElement::style()
-{
-    return ensureInlineStyleDecl();
-}
-
 void StyledElement::removeCSSProperty(Attribute* attribute, int id)
 {
     if (!attribute->decl())
@@ -444,9 +417,8 @@
 
 void StyledElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
 {
-    if (!m_inlineStyleDecl)
-        return;
-    m_inlineStyleDecl->addSubresourceStyleURLs(urls);
+    if (CSSMutableStyleDeclaration* inlineStyle = inlineStyleDecl())
+        inlineStyle->addSubresourceStyleURLs(urls);
 }
 
 }

Modified: trunk/Source/WebCore/dom/StyledElement.h (106434 => 106435)


--- trunk/Source/WebCore/dom/StyledElement.h	2012-02-01 06:55:17 UTC (rev 106434)
+++ trunk/Source/WebCore/dom/StyledElement.h	2012-02-01 07:36:21 UTC (rev 106435)
@@ -58,9 +58,9 @@
     virtual PassRefPtr<CSSMutableStyleDeclaration> additionalAttributeStyle() { return 0; }
     void invalidateStyleAttribute();
 
-    CSSMutableStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
-    CSSMutableStyleDeclaration* ensureInlineStyleDecl();
-    virtual CSSStyleDeclaration* style() OVERRIDE;
+    CSSMutableStyleDeclaration* inlineStyleDecl() const { return attributeMap() ? attributeMap()->inlineStyleDecl() : 0; }
+    CSSMutableStyleDeclaration* ensureInlineStyleDecl() { return ensureAttributeMap()->ensureInlineStyleDecl(); }
+    virtual CSSStyleDeclaration* style() OVERRIDE { return ensureInlineStyleDecl(); }
 
     const SpaceSplitString& classNames() const;
 
@@ -88,11 +88,13 @@
 private:
     void createMappedDecl(Attribute*);
 
-    void createInlineStyleDecl();
-    void destroyInlineStyleDecl();
     virtual void updateStyleAttribute() const;
 
-    RefPtr<CSSMutableStyleDeclaration> m_inlineStyleDecl;
+    void destroyInlineStyleDecl()
+    {
+        if (attributeMap())
+            attributeMap()->destroyInlineStyleDecl();
+    }
 };
 
 inline const SpaceSplitString& StyledElement::classNames() const
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to