Title: [126524] trunk/Source/WebCore
Revision
126524
Author
[email protected]
Date
2012-08-23 18:25:21 -0700 (Thu, 23 Aug 2012)

Log Message

Use immutable StylePropertySets for element inline style declarations.
<http://webkit.org/b/94714>

Reviewed by Antti Koivisto.

Construct the inline styles as immutable StylePropertySets initially (until they are
modified through CSSOM APIs), reducing their memory footprint and enabling us to do
sharing optimizations in the future.

* css/CSSParser.cpp:
(WebCore::CSSParser::parseInlineStyleDeclaration):
(WebCore::CSSParser::parseDeclaration):
* css/CSSParser.h:
* dom/ElementAttributeData.cpp:
(WebCore::ElementAttributeData::updateInlineStyleAvoidingMutation):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (126523 => 126524)


--- trunk/Source/WebCore/ChangeLog	2012-08-24 01:19:50 UTC (rev 126523)
+++ trunk/Source/WebCore/ChangeLog	2012-08-24 01:25:21 UTC (rev 126524)
@@ -1,3 +1,21 @@
+2012-08-23  Andreas Kling  <[email protected]>
+
+        Use immutable StylePropertySets for element inline style declarations.
+        <http://webkit.org/b/94714>
+
+        Reviewed by Antti Koivisto.
+
+        Construct the inline styles as immutable StylePropertySets initially (until they are
+        modified through CSSOM APIs), reducing their memory footprint and enabling us to do
+        sharing optimizations in the future.
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseInlineStyleDeclaration):
+        (WebCore::CSSParser::parseDeclaration):
+        * css/CSSParser.h:
+        * dom/ElementAttributeData.cpp:
+        (WebCore::ElementAttributeData::updateInlineStyleAvoidingMutation):
+
 2012-08-23  Adam Barth  <[email protected]>
 
         [V8] V8AbstractEventListener re-implements ScopedPersistent by hand

Modified: trunk/Source/WebCore/css/CSSParser.cpp (126523 => 126524)


--- trunk/Source/WebCore/css/CSSParser.cpp	2012-08-24 01:19:50 UTC (rev 126523)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2012-08-24 01:25:21 UTC (rev 126524)
@@ -46,6 +46,7 @@
 #include "CSSPropertySourceData.h"
 #include "CSSReflectValue.h"
 #include "CSSSelector.h"
+#include "CSSStyleSheet.h"
 #include "CSSTimingFunctionValue.h"
 #include "CSSUnicodeRangeValue.h"
 #include "CSSValueKeywords.h"
@@ -1242,6 +1243,30 @@
     m_selectorListForParseSelector = 0;
 }
 
+PassRefPtr<StylePropertySet> CSSParser::parseInlineStyleDeclaration(const String& string, Element* element)
+{
+    CSSParserContext context = element->document()->elementSheet()->contents()->parserContext();
+    context.mode = strictToCSSParserMode(element->isHTMLElement() && !element->document()->inQuirksMode());
+    return CSSParser(context).parseDeclaration(string, element->document()->elementSheet()->contents());
+}
+
+PassRefPtr<StylePropertySet> CSSParser::parseDeclaration(const String& string, StyleSheetContents* contextStyleSheet)
+{
+    setStyleSheet(contextStyleSheet);
+
+    setupParser("@-webkit-decls{", string, "} ");
+    cssyyparse(this);
+    m_rule = 0;
+
+    if (m_hasFontFaceOnlyValues)
+        deleteFontFaceOnlyValues();
+
+    RefPtr<StylePropertySet> style = createStylePropertySet();
+    clearProperties();
+    return style.release();
+}
+
+
 bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, PassRefPtr<CSSRuleSourceData> prpRuleSourceData, StyleSheetContents* contextStyleSheet)
 {
     // Length of the "@-webkit-decls{" prefix.

Modified: trunk/Source/WebCore/css/CSSParser.h (126523 => 126524)


--- trunk/Source/WebCore/css/CSSParser.h	2012-08-24 01:19:50 UTC (rev 126523)
+++ trunk/Source/WebCore/css/CSSParser.h	2012-08-24 01:25:21 UTC (rev 126524)
@@ -53,6 +53,7 @@
 class CSSValueList;
 class CSSWrapShape;
 class Document;
+class Element;
 class MediaQueryExp;
 class MediaQuerySet;
 class StyleKeyframe;
@@ -83,6 +84,7 @@
     static PassRefPtr<CSSValueList> parseFontFaceValue(const AtomicString&);
     PassRefPtr<CSSPrimitiveValue> parseValidPrimitive(int ident, CSSParserValue*);
     bool parseDeclaration(StylePropertySet*, const String&, PassRefPtr<CSSRuleSourceData>, StyleSheetContents* contextStyleSheet);
+    static PassRefPtr<StylePropertySet> parseInlineStyleDeclaration(const String&, Element*);
     PassOwnPtr<MediaQuery> parseMediaQuery(const String&);
 
     void addProperty(CSSPropertyID, PassRefPtr<CSSValue>, bool important, bool implicit = false);
@@ -402,6 +404,7 @@
     bool parseGeneratedImage(CSSParserValueList*, RefPtr<CSSValue>&);
 
     bool parseValue(StylePropertySet*, CSSPropertyID, const String&, bool important, StyleSheetContents* contextStyleSheet);
+    PassRefPtr<StylePropertySet> parseDeclaration(const String&, StyleSheetContents* contextStyleSheet);
 
     enum SizeParameterType {
         None,

Modified: trunk/Source/WebCore/dom/ElementAttributeData.cpp (126523 => 126524)


--- trunk/Source/WebCore/dom/ElementAttributeData.cpp	2012-08-24 01:19:50 UTC (rev 126523)
+++ trunk/Source/WebCore/dom/ElementAttributeData.cpp	2012-08-24 01:25:21 UTC (rev 126524)
@@ -27,6 +27,7 @@
 #include "ElementAttributeData.h"
 
 #include "Attr.h"
+#include "CSSParser.h"
 #include "CSSStyleSheet.h"
 #include "MemoryInstrumentation.h"
 #include "StyledElement.h"
@@ -211,8 +212,9 @@
     if (m_inlineStyleDecl && !m_inlineStyleDecl->isMutable())
         m_inlineStyleDecl.clear();
     if (!m_inlineStyleDecl)
-        m_inlineStyleDecl = StylePropertySet::create(strictToCSSParserMode(element->isHTMLElement() && !element->document()->inQuirksMode()));
-    m_inlineStyleDecl->parseDeclaration(text, element->document()->elementSheet()->contents());
+        m_inlineStyleDecl = CSSParser::parseInlineStyleDeclaration(text, element);
+    else
+        m_inlineStyleDecl->parseDeclaration(text, element->document()->elementSheet()->contents());
 }
 
 void ElementAttributeData::destroyInlineStyle(StyledElement* element) const
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to