Title: [105738] trunk/Source/WebCore
Revision
105738
Author
kl...@webkit.org
Date
2012-01-24 07:42:07 -0800 (Tue, 24 Jan 2012)

Log Message

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

Reviewed by Antti Koivisto.

Move the inline style declaration from StyledElement to NamedNodeMap, 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>.

* dom/NamedNodeMap.cpp:
(WebCore::NamedNodeMap::ensureInlineStyleDecl):
(WebCore::NamedNodeMap::destroyInlineStyleDecl):
(WebCore::NamedNodeMap::createInlineStyleDecl):
* dom/NamedNodeMap.h:
(WebCore::NamedNodeMap::inlineStyleDecl):
* dom/StyledElement.cpp:
(WebCore::StyledElement::updateStyleAttribute):
(WebCore::StyledElement::addSubresourceAttributeURLs):
* dom/StyledElement.h:
(WebCore::StyledElement::inlineStyleDecl):
(WebCore::StyledElement::ensureInlineStyleDecl):
(WebCore::StyledElement::destroyInlineStyleDecl):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (105737 => 105738)


--- trunk/Source/WebCore/ChangeLog	2012-01-24 15:17:11 UTC (rev 105737)
+++ trunk/Source/WebCore/ChangeLog	2012-01-24 15:42:07 UTC (rev 105738)
@@ -1,3 +1,31 @@
+2012-01-23  Andreas Kling  <awesomekl...@apple.com>
+
+        Make elements that don't have attributes smaller.
+        <http://webkit.org/b/76876>
+
+        Reviewed by Antti Koivisto.
+
+        Move the inline style declaration from StyledElement to NamedNodeMap, 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>.
+
+        * dom/NamedNodeMap.cpp:
+        (WebCore::NamedNodeMap::ensureInlineStyleDecl):
+        (WebCore::NamedNodeMap::destroyInlineStyleDecl):
+        (WebCore::NamedNodeMap::createInlineStyleDecl):
+        * dom/NamedNodeMap.h:
+        (WebCore::NamedNodeMap::inlineStyleDecl):
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::updateStyleAttribute):
+        (WebCore::StyledElement::addSubresourceAttributeURLs):
+        * dom/StyledElement.h:
+        (WebCore::StyledElement::inlineStyleDecl):
+        (WebCore::StyledElement::ensureInlineStyleDecl):
+        (WebCore::StyledElement::destroyInlineStyleDecl):
+
 2012-01-24  No'am Rosenthal  <noam.rosent...@nokia.com>
 
         [Qt][WK2] Qt's cross-process AC copies images excessively when updating tiles.

Modified: trunk/Source/WebCore/dom/NamedNodeMap.cpp (105737 => 105738)


--- trunk/Source/WebCore/dom/NamedNodeMap.cpp	2012-01-24 15:17:11 UTC (rev 105737)
+++ trunk/Source/WebCore/dom/NamedNodeMap.cpp	2012-01-24 15:42:07 UTC (rev 105738)
@@ -27,9 +27,9 @@
 
 #include "Attr.h"
 #include "Document.h"
-#include "Element.h"
 #include "ExceptionCode.h"
 #include "HTMLNames.h"
+#include "StyledElement.h"
 
 namespace WebCore {
 
@@ -330,4 +330,27 @@
     return true;
 }
 
+CSSMutableStyleDeclaration* NamedNodeMap::ensureInlineStyleDecl()
+{
+    if (!m_inlineStyleDecl)
+        createInlineStyleDecl();
+    return m_inlineStyleDecl.get();
+}
+
+void NamedNodeMap::destroyInlineStyleDecl()
+{
+    if (!m_inlineStyleDecl)
+        return;
+    m_inlineStyleDecl->clearParentElement();
+    m_inlineStyleDecl = 0;
+}
+
+void NamedNodeMap::createInlineStyleDecl()
+{
+    ASSERT(!m_inlineStyleDecl);
+    ASSERT(m_element->isStyledElement());
+    m_inlineStyleDecl = CSSMutableStyleDeclaration::createInline(static_cast<StyledElement*>(m_element));
+    m_inlineStyleDecl->setStrictParsing(m_element->isHTMLElement() && !m_element->document()->inQuirksMode());
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/NamedNodeMap.h (105737 => 105738)


--- trunk/Source/WebCore/dom/NamedNodeMap.h	2012-01-24 15:17:11 UTC (rev 105737)
+++ trunk/Source/WebCore/dom/NamedNodeMap.h	2012-01-24 15:42:07 UTC (rev 105738)
@@ -102,6 +102,10 @@
 
     size_t mappedAttributeCount() const;
 
+    CSSMutableStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
+    CSSMutableStyleDeclaration* ensureInlineStyleDecl();
+    void destroyInlineStyleDecl();
+
 private:
     NamedNodeMap(Element* element)
         : m_element(element)
@@ -116,11 +120,17 @@
     void setAttributes(const NamedNodeMap&);
     void clearAttributes();
     void replaceAttribute(size_t index, PassRefPtr<Attribute>);
+    void createInlineStyleDecl();
 
+    // FIXME: NamedNodeMap should be broken up into two classes, one containing data
+    //        for elements with attributes, and one for exposure to the DOM.
+    //        See <http://webkit.org/b/75069> for more information.
+
     SpaceSplitString m_classNames;
     Element* m_element;
     Vector<RefPtr<Attribute>, 4> m_attributes;
     AtomicString m_idForStyleResolution;
+    RefPtr<CSSMutableStyleDeclaration> m_inlineStyleDecl;
 };
 
 inline Attribute* NamedNodeMap::getAttributeItem(const QualifiedName& name) const

Modified: trunk/Source/WebCore/dom/StyledElement.cpp (105737 => 105738)


--- trunk/Source/WebCore/dom/StyledElement.cpp	2012-01-24 15:17:11 UTC (rev 105737)
+++ trunk/Source/WebCore/dom/StyledElement.cpp	2012-01-24 15:42:07 UTC (rev 105738)
@@ -112,8 +112,8 @@
     ASSERT(!isStyleAttributeValid());
     setIsStyleAttributeValid();
     setIsSynchronizingStyleAttribute();
-    if (m_inlineStyleDecl)
-        const_cast<StyledElement*>(this)->setAttribute(styleAttr, m_inlineStyleDecl->cssText());
+    if (CSSMutableStyleDeclaration* inlineStyle = inlineStyleDecl())
+        const_cast<StyledElement*>(this)->setAttribute(styleAttr, inlineStyle->cssText());
     clearIsSynchronizingStyleAttribute();
 }
 
@@ -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)
@@ -240,18 +225,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())
@@ -443,9 +416,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 (105737 => 105738)


--- trunk/Source/WebCore/dom/StyledElement.h	2012-01-24 15:17:11 UTC (rev 105737)
+++ trunk/Source/WebCore/dom/StyledElement.h	2012-01-24 15:42:07 UTC (rev 105738)
@@ -59,9 +59,9 @@
     virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&) { }
     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 attributes(false)->ensureInlineStyleDecl(); }
+    virtual CSSStyleDeclaration* style() OVERRIDE { return ensureInlineStyleDecl(); }
 
     const SpaceSplitString& classNames() const;
 
@@ -89,11 +89,8 @@
 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