Changeset 105999 in webkit


Ignore:
Timestamp:
Jan 26, 2012 6:56:34 AM (12 years ago)
Author:
kling@webkit.org
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):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r105997 r105999  
     12012-01-23  Andreas Kling  <awesomekling@apple.com>
     2
     3        Make elements that don't have attributes smaller.
     4        <http://webkit.org/b/76876>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Move the inline style declaration from StyledElement to NamedNodeMap, since having
     9        an inline style declaration also implies having a style attribute on the element.
     10        This saves one CPU word per element that has no attributes.
     11
     12        This reduces memory consumption by 412 kB (on 64-bit) when viewing the full
     13        HTML5 spec at <http://whatwg.org/c>.
     14
     15        * dom/NamedNodeMap.cpp:
     16        (WebCore::NamedNodeMap::ensureInlineStyleDecl):
     17        (WebCore::NamedNodeMap::destroyInlineStyleDecl):
     18        (WebCore::NamedNodeMap::createInlineStyleDecl):
     19        * dom/NamedNodeMap.h:
     20        (WebCore::NamedNodeMap::inlineStyleDecl):
     21        * dom/StyledElement.cpp:
     22        (WebCore::StyledElement::updateStyleAttribute):
     23        (WebCore::StyledElement::addSubresourceAttributeURLs):
     24        * dom/StyledElement.h:
     25        (WebCore::StyledElement::inlineStyleDecl):
     26        (WebCore::StyledElement::ensureInlineStyleDecl):
     27        (WebCore::StyledElement::destroyInlineStyleDecl):
     28
    1292012-01-26  Jesus Sanchez-Palencia  <jesus.palencia@openbossa.org>
    230
  • trunk/Source/WebCore/dom/NamedNodeMap.cpp

    r105773 r105999  
    2828#include "Attr.h"
    2929#include "Document.h"
    30 #include "Element.h"
    3130#include "ExceptionCode.h"
    3231#include "HTMLNames.h"
     32#include "StyledElement.h"
    3333
    3434namespace WebCore {
     
    331331}
    332332
     333CSSMutableStyleDeclaration* NamedNodeMap::ensureInlineStyleDecl()
     334{
     335    if (!m_inlineStyleDecl)
     336        createInlineStyleDecl();
     337    return m_inlineStyleDecl.get();
     338}
     339
     340void NamedNodeMap::destroyInlineStyleDecl()
     341{
     342    if (!m_inlineStyleDecl)
     343        return;
     344    m_inlineStyleDecl->clearParentElement();
     345    m_inlineStyleDecl = 0;
     346}
     347
     348void NamedNodeMap::createInlineStyleDecl()
     349{
     350    ASSERT(!m_inlineStyleDecl);
     351    ASSERT(m_element->isStyledElement());
     352    m_inlineStyleDecl = CSSMutableStyleDeclaration::createInline(static_cast<StyledElement*>(m_element));
     353    m_inlineStyleDecl->setStrictParsing(m_element->isHTMLElement() && !m_element->document()->inQuirksMode());
     354}
     355
    333356} // namespace WebCore
  • trunk/Source/WebCore/dom/NamedNodeMap.h

    r105773 r105999  
    102102
    103103    size_t mappedAttributeCount() const;
     104
     105    CSSMutableStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
     106    CSSMutableStyleDeclaration* ensureInlineStyleDecl();
     107    void destroyInlineStyleDecl();
    104108
    105109private:
     
    117121    void clearAttributes();
    118122    void replaceAttribute(size_t index, PassRefPtr<Attribute>);
    119 
     123    void createInlineStyleDecl();
     124
     125    // FIXME: NamedNodeMap should be broken up into two classes, one containing data
     126    //        for elements with attributes, and one for exposure to the DOM.
     127    //        See <http://webkit.org/b/75069> for more information.
    120128    SpaceSplitString m_classNames;
    121129    Element* m_element;
    122130    Vector<RefPtr<Attribute>, 4> m_attributes;
    123131    AtomicString m_idForStyleResolution;
     132    RefPtr<CSSMutableStyleDeclaration> m_inlineStyleDecl;
    124133};
    125134
  • trunk/Source/WebCore/dom/StyledElement.cpp

    r105773 r105999  
    113113    setIsStyleAttributeValid();
    114114    setIsSynchronizingStyleAttribute();
    115     if (m_inlineStyleDecl)
    116         const_cast<StyledElement*>(this)->setAttribute(styleAttr, m_inlineStyleDecl->cssText());
     115    if (CSSMutableStyleDeclaration* inlineStyle = inlineStyleDecl())
     116        const_cast<StyledElement*>(this)->setAttribute(styleAttr, inlineStyle->cssText());
    117117    clearIsSynchronizingStyleAttribute();
    118118}
     
    126126{
    127127    return Attribute::createMapped(name, value);
    128 }
    129 
    130 void StyledElement::createInlineStyleDecl()
    131 {
    132     ASSERT(!m_inlineStyleDecl);
    133     m_inlineStyleDecl = CSSMutableStyleDeclaration::createInline(this);
    134     m_inlineStyleDecl->setStrictParsing(isHTMLElement() && !document()->inQuirksMode());
    135 }
    136 
    137 void StyledElement::destroyInlineStyleDecl()
    138 {
    139     if (!m_inlineStyleDecl)
    140         return;
    141     m_inlineStyleDecl->clearParentElement();
    142     m_inlineStyleDecl = 0;
    143128}
    144129
     
    239224        setNeedsStyleRecalc();
    240225    }
    241 }
    242 
    243 CSSMutableStyleDeclaration* StyledElement::ensureInlineStyleDecl()
    244 {
    245     if (!m_inlineStyleDecl)
    246         createInlineStyleDecl();
    247     return m_inlineStyleDecl.get();
    248 }
    249 
    250 CSSStyleDeclaration* StyledElement::style()
    251 {
    252     return ensureInlineStyleDecl();
    253226}
    254227
     
    444417void StyledElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
    445418{
    446     if (!m_inlineStyleDecl)
    447         return;
    448     m_inlineStyleDecl->addSubresourceStyleURLs(urls);
    449 }
    450 
    451 }
     419    if (CSSMutableStyleDeclaration* inlineStyle = inlineStyleDecl())
     420        inlineStyle->addSubresourceStyleURLs(urls);
     421}
     422
     423}
  • trunk/Source/WebCore/dom/StyledElement.h

    r105773 r105999  
    6060    void invalidateStyleAttribute();
    6161
    62     CSSMutableStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
    63     CSSMutableStyleDeclaration* ensureInlineStyleDecl();
    64     virtual CSSStyleDeclaration* style() OVERRIDE;
     62    CSSMutableStyleDeclaration* inlineStyleDecl() const { return attributeMap() ? attributeMap()->inlineStyleDecl() : 0; }
     63    CSSMutableStyleDeclaration* ensureInlineStyleDecl() { return attributes(false)->ensureInlineStyleDecl(); }
     64    virtual CSSStyleDeclaration* style() OVERRIDE { return ensureInlineStyleDecl(); }
    6565
    6666    const SpaceSplitString& classNames() const;
     
    9090    void createMappedDecl(Attribute*);
    9191
    92     void createInlineStyleDecl();
    93     void destroyInlineStyleDecl();
    9492    virtual void updateStyleAttribute() const;
    95 
    96     RefPtr<CSSMutableStyleDeclaration> m_inlineStyleDecl;
     93    void destroyInlineStyleDecl() { if (attributeMap()) attributeMap()->destroyInlineStyleDecl(); }
    9794};
    9895
Note: See TracChangeset for help on using the changeset viewer.