From 324cb0bfcbaedb15a068086a8d4fadea1895d6d4 Mon Sep 17 00:00:00 2001 From: "kling@webkit.org" Date: Tue, 24 Jan 2012 15:42:07 +0000 Subject: [PATCH] Make elements that don't have attributes smaller. 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 . * 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): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105738 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 28 ++++++++++++++++++++++++++++ Source/WebCore/dom/NamedNodeMap.cpp | 25 ++++++++++++++++++++++++- Source/WebCore/dom/NamedNodeMap.h | 10 ++++++++++ Source/WebCore/dom/StyledElement.cpp | 36 ++++-------------------------------- Source/WebCore/dom/StyledElement.h | 11 ++++------- 5 files changed, 70 insertions(+), 40 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index a1f7f76..d11b222 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,31 @@ +2012-01-23 Andreas Kling + + Make elements that don't have attributes smaller. + + + 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 . + + * 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 [Qt][WK2] Qt's cross-process AC copies images excessively when updating tiles. diff --git a/Source/WebCore/dom/NamedNodeMap.cpp b/Source/WebCore/dom/NamedNodeMap.cpp index 1b6aca0..9b72488 100644 --- a/Source/WebCore/dom/NamedNodeMap.cpp +++ b/Source/WebCore/dom/NamedNodeMap.cpp @@ -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 @@ bool NamedNodeMap::mapsEquivalent(const NamedNodeMap* otherMap) const 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(m_element)); + m_inlineStyleDecl->setStrictParsing(m_element->isHTMLElement() && !m_element->document()->inQuirksMode()); +} + } // namespace WebCore diff --git a/Source/WebCore/dom/NamedNodeMap.h b/Source/WebCore/dom/NamedNodeMap.h index 0905d64..c247867 100644 --- a/Source/WebCore/dom/NamedNodeMap.h +++ b/Source/WebCore/dom/NamedNodeMap.h @@ -102,6 +102,10 @@ public: 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 @@ private: void setAttributes(const NamedNodeMap&); void clearAttributes(); void replaceAttribute(size_t index, PassRefPtr); + 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 for more information. SpaceSplitString m_classNames; Element* m_element; Vector, 4> m_attributes; AtomicString m_idForStyleResolution; + RefPtr m_inlineStyleDecl; }; inline Attribute* NamedNodeMap::getAttributeItem(const QualifiedName& name) const diff --git a/Source/WebCore/dom/StyledElement.cpp b/Source/WebCore/dom/StyledElement.cpp index abbd782..8bee53d 100644 --- a/Source/WebCore/dom/StyledElement.cpp +++ b/Source/WebCore/dom/StyledElement.cpp @@ -112,8 +112,8 @@ void StyledElement::updateStyleAttribute() const ASSERT(!isStyleAttributeValid()); setIsStyleAttributeValid(); setIsSynchronizingStyleAttribute(); - if (m_inlineStyleDecl) - const_cast(this)->setAttribute(styleAttr, m_inlineStyleDecl->cssText()); + if (CSSMutableStyleDeclaration* inlineStyle = inlineStyleDecl()) + const_cast(this)->setAttribute(styleAttr, inlineStyle->cssText()); clearIsSynchronizingStyleAttribute(); } @@ -127,21 +127,6 @@ PassRefPtr StyledElement::createAttribute(const QualifiedName& name, 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 @@ void StyledElement::parseMappedAttribute(Attribute* attr) } } -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::copyNonAttributeProperties(const Element* sourceElement) void StyledElement::addSubresourceAttributeURLs(ListHashSet& urls) const { - if (!m_inlineStyleDecl) - return; - m_inlineStyleDecl->addSubresourceStyleURLs(urls); + if (CSSMutableStyleDeclaration* inlineStyle = inlineStyleDecl()) + inlineStyle->addSubresourceStyleURLs(urls); } } diff --git a/Source/WebCore/dom/StyledElement.h b/Source/WebCore/dom/StyledElement.h index a5dcbc8..c434988 100644 --- a/Source/WebCore/dom/StyledElement.h +++ b/Source/WebCore/dom/StyledElement.h @@ -59,9 +59,9 @@ public: virtual void additionalAttributeStyleDecls(Vector&) { } 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 @@ protected: private: void createMappedDecl(Attribute*); - void createInlineStyleDecl(); - void destroyInlineStyleDecl(); virtual void updateStyleAttribute() const; - - RefPtr m_inlineStyleDecl; + void destroyInlineStyleDecl() { if (attributeMap()) attributeMap()->destroyInlineStyleDecl(); } }; inline const SpaceSplitString& StyledElement::classNames() const -- 2.7.4