<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):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105999
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2012-01-23 Andreas Kling <awesomekling@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-26 Jesus Sanchez-Palencia <jesus.palencia@openbossa.org>
[Qt] Use ICU if available
#include "Attr.h"
#include "Document.h"
-#include "Element.h"
#include "ExceptionCode.h"
#include "HTMLNames.h"
+#include "StyledElement.h"
namespace WebCore {
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
size_t mappedAttributeCount() const;
+ CSSMutableStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
+ CSSMutableStyleDeclaration* ensureInlineStyleDecl();
+ void destroyInlineStyleDecl();
+
private:
NamedNodeMap(Element* element)
: m_element(element)
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
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();
}
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)
}
}
-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())
void StyledElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
{
- if (!m_inlineStyleDecl)
- return;
- m_inlineStyleDecl->addSubresourceStyleURLs(urls);
+ if (CSSMutableStyleDeclaration* inlineStyle = inlineStyleDecl())
+ inlineStyle->addSubresourceStyleURLs(urls);
}
}
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;
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