Title: [125934] trunk/Source/WebCore
Revision
125934
Author
[email protected]
Date
2012-08-17 14:24:15 -0700 (Fri, 17 Aug 2012)

Log Message

Share the StringImpl the CSS property names
https://bugs.webkit.org/show_bug.cgi?id=94187

Patch by Benjamin Poulain <[email protected]> on 2012-08-17
Reviewed by Alexey Proskuryakov.

Previously, we would instanciate a new String every time a CSS property name was needed.

This patches moves the creation of the AtomicString to CSSPropertyNames and reuse that
StringImpl whenever needed.

With the patch, accessing CSS property names from _javascript_ gets about 2.1 times faster.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
(WebCore::CSSComputedStyleDeclaration::item):
* css/CSSPrimitiveValue.cpp:
(WebCore::valueOrPropertyName):
* css/CSSProperty.cpp:
(WebCore::CSSProperty::cssName):
* css/PropertySetCSSStyleDeclaration.cpp:
(WebCore::PropertySetCSSStyleDeclaration::item):
(WebCore::PropertySetCSSStyleDeclaration::getPropertyShorthand):
* css/makeprop.pl:
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::getSupportedCSSProperties):
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyle::styleWithProperties):
* page/animation/ImplicitAnimation.cpp:
(WebCore::ImplicitAnimation::sendTransitionEvent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (125933 => 125934)


--- trunk/Source/WebCore/ChangeLog	2012-08-17 21:16:44 UTC (rev 125933)
+++ trunk/Source/WebCore/ChangeLog	2012-08-17 21:24:15 UTC (rev 125934)
@@ -1,3 +1,35 @@
+2012-08-17  Benjamin Poulain  <[email protected]>
+
+        Share the StringImpl the CSS property names
+        https://bugs.webkit.org/show_bug.cgi?id=94187
+
+        Reviewed by Alexey Proskuryakov.
+
+        Previously, we would instanciate a new String every time a CSS property name was needed.
+
+        This patches moves the creation of the AtomicString to CSSPropertyNames and reuse that
+        StringImpl whenever needed.
+
+        With the patch, accessing CSS property names from _javascript_ gets about 2.1 times faster.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
+        (WebCore::CSSComputedStyleDeclaration::item):
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::valueOrPropertyName):
+        * css/CSSProperty.cpp:
+        (WebCore::CSSProperty::cssName):
+        * css/PropertySetCSSStyleDeclaration.cpp:
+        (WebCore::PropertySetCSSStyleDeclaration::item):
+        (WebCore::PropertySetCSSStyleDeclaration::getPropertyShorthand):
+        * css/makeprop.pl:
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::getSupportedCSSProperties):
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::InspectorStyle::styleWithProperties):
+        * page/animation/ImplicitAnimation.cpp:
+        (WebCore::ImplicitAnimation::sendTransitionEvent):
+
 2012-08-16  James Robinson  <[email protected]>
 
         [chromium] Add Source/WebCore/platform/graphics/chromium/cc/ to include path and remove cc/ prefix from includes

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (125933 => 125934)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2012-08-17 21:16:44 UTC (rev 125933)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2012-08-17 21:24:15 UTC (rev 125934)
@@ -2355,7 +2355,7 @@
                     else if (animation->animationMode() == Animation::AnimateAll)
                         propertyValue = cssValuePool().createIdentifierValue(CSSValueAll);
                     else
-                        propertyValue = cssValuePool().createValue(getPropertyName(animation->property()), CSSPrimitiveValue::CSS_STRING);
+                        propertyValue = cssValuePool().createValue(getPropertyNameString(animation->property()), CSSPrimitiveValue::CSS_STRING);
                     list->append(propertyValue);
                 }
             } else
@@ -2631,7 +2631,7 @@
     if (i >= length())
         return "";
 
-    return getPropertyName(computedProperties[i]);
+    return getPropertyNameString(computedProperties[i]);
 }
 
 bool CSSComputedStyleDeclaration::cssPropertyMatches(const CSSProperty* property) const

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (125933 => 125934)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2012-08-17 21:16:44 UTC (rev 125933)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2012-08-17 21:24:15 UTC (rev 125934)
@@ -207,15 +207,7 @@
         return keywordString;
     }
 
-    if (valueOrPropertyID >= firstCSSProperty && valueOrPropertyID < firstCSSProperty + numCSSProperties) {
-        static AtomicString* propertyStrings = new AtomicString[numCSSProperties]; // Leaked intentionally.
-        AtomicString& propertyString = propertyStrings[valueOrPropertyID - firstCSSProperty];
-        if (propertyString.isNull())
-            propertyString = getPropertyName(static_cast<CSSPropertyID>(valueOrPropertyID));
-        return propertyString;
-    }
-
-    return nullAtom;
+    return getPropertyNameAtomicString(static_cast<CSSPropertyID>(valueOrPropertyID));
 }
 
 CSSPrimitiveValue::CSSPrimitiveValue(int ident)

Modified: trunk/Source/WebCore/css/CSSProperty.cpp (125933 => 125934)


--- trunk/Source/WebCore/css/CSSProperty.cpp	2012-08-17 21:16:44 UTC (rev 125933)
+++ trunk/Source/WebCore/css/CSSProperty.cpp	2012-08-17 21:24:15 UTC (rev 125934)
@@ -48,7 +48,7 @@
         return "-webkit-var-" + static_cast<CSSVariableValue*>(value())->name();
     }
 #endif
-    return String(getPropertyName(id()));
+    return getPropertyNameString(id());
 }
 
 String CSSProperty::cssText() const

Modified: trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp (125933 => 125934)


--- trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp	2012-08-17 21:16:44 UTC (rev 125933)
+++ trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp	2012-08-17 21:24:15 UTC (rev 125934)
@@ -148,7 +148,7 @@
 {
     if (i >= m_propertySet->propertyCount())
         return "";
-    return getPropertyName(m_propertySet->propertyAt(i).id());
+    return getPropertyNameString(m_propertySet->propertyAt(i).id());
 }
 
 String PropertySetCSSStyleDeclaration::cssText() const
@@ -206,7 +206,7 @@
     CSSPropertyID shorthandID = m_propertySet->getPropertyShorthand(propertyID);
     if (!shorthandID)
         return String();
-    return getPropertyName(shorthandID);
+    return getPropertyNameString(shorthandID);
 }
 
 bool PropertySetCSSStyleDeclaration::isPropertyImplicit(const String& propertyName)

Modified: trunk/Source/WebCore/css/makeprop.pl (125933 => 125934)


--- trunk/Source/WebCore/css/makeprop.pl	2012-08-17 21:16:44 UTC (rev 125933)
+++ trunk/Source/WebCore/css/makeprop.pl	2012-08-17 21:24:15 UTC (rev 125934)
@@ -70,6 +70,7 @@
 #include <string.h>
 
 #include <wtf/ASCIICType.h>
+#include <wtf/text/AtomicString.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -129,8 +130,31 @@
     return propertyNameStrings[index];
 }
 
-WTF::String getJSPropertyName(CSSPropertyID id)
+const AtomicString& getPropertyNameAtomicString(CSSPropertyID id)
 {
+    if (id < firstCSSProperty)
+        return nullAtom;
+    int index = id - firstCSSProperty;
+    if (index >= numCSSProperties)
+        return nullAtom;
+
+    static AtomicString* propertyStrings = new AtomicString[numCSSProperties]; // Intentionally never destroyed.
+    AtomicString& propertyString = propertyStrings[index];
+    if (propertyString.isNull()) {
+        const char* propertyName = propertyNameStrings[index];
+        propertyString = AtomicString(propertyName, strlen(propertyName), AtomicString::ConstructFromLiteral);
+    }
+    return propertyString;
+}
+
+String getPropertyNameString(CSSPropertyID id)
+{
+    // We share the StringImpl with the AtomicStrings.
+    return getPropertyNameAtomicString(id).string();
+}
+
+String getJSPropertyName(CSSPropertyID id)
+{
     char result[maxCSSPropertyNameLength + 1];
     const char* cssPropertyName = getPropertyName(id);
     const char* propertyNamePointer = cssPropertyName;
@@ -166,6 +190,7 @@
 #include <wtf/HashTraits.h>
 
 namespace WTF {
+class AtomicString;
 class String;
 }
 
@@ -202,6 +227,8 @@
 print HEADER << "EOF";
 
 const char* getPropertyName(CSSPropertyID);
+const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID id);
+WTF::String getPropertyNameString(CSSPropertyID id);
 WTF::String getJSPropertyName(CSSPropertyID);
 
 inline CSSPropertyID convertToCSSPropertyID(int value)

Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp (125933 => 125934)


--- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp	2012-08-17 21:16:44 UTC (rev 125933)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp	2012-08-17 21:24:15 UTC (rev 125934)
@@ -783,7 +783,7 @@
     for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) {
         CSSPropertyID id = convertToCSSPropertyID(i);
         RefPtr<TypeBuilder::CSS::CSSPropertyInfo> property = TypeBuilder::CSS::CSSPropertyInfo::create()
-            .setName(getPropertyName(id));
+            .setName(getPropertyNameString(id));
 
         const StylePropertyShorthand& shorthand = shorthandForProperty(id);
         if (!shorthand.length()) {
@@ -793,7 +793,7 @@
         RefPtr<TypeBuilder::Array<String> > longhands = TypeBuilder::Array<String>::create();
         for (unsigned j = 0; j < shorthand.length(); ++j) {
             CSSPropertyID longhandID = shorthand.properties()[j];
-            longhands->addItem(getPropertyName(longhandID));
+            longhands->addItem(getPropertyNameString(longhandID));
         }
         property->setLonghands(longhands);
         properties->addItem(property.release());

Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (125933 => 125934)


--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2012-08-17 21:16:44 UTC (rev 125933)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2012-08-17 21:24:15 UTC (rev 125934)
@@ -528,7 +528,7 @@
                 bool shouldInactivate = false;
                 CSSPropertyID propertyId = cssPropertyID(name);
                 // Canonicalize property names to treat non-prefixed and vendor-prefixed property names the same (opacity vs. -webkit-opacity).
-                String canonicalPropertyName = propertyId ? String(getPropertyName(propertyId)) : name;
+                String canonicalPropertyName = propertyId ? getPropertyNameString(propertyId) : name;
                 HashMap<String, RefPtr<TypeBuilder::CSS::CSSProperty> >::iterator activeIt = propertyNameToPreviousActiveProperty.find(canonicalPropertyName);
                 if (activeIt != propertyNameToPreviousActiveProperty.end()) {
                     if (propertyEntry.parsedOk)

Modified: trunk/Source/WebCore/page/animation/ImplicitAnimation.cpp (125933 => 125934)


--- trunk/Source/WebCore/page/animation/ImplicitAnimation.cpp	2012-08-17 21:16:44 UTC (rev 125933)
+++ trunk/Source/WebCore/page/animation/ImplicitAnimation.cpp	2012-08-17 21:24:15 UTC (rev 125934)
@@ -161,7 +161,7 @@
         Document::ListenerType listenerType = Document::TRANSITIONEND_LISTENER;
 
         if (shouldSendEventForListener(listenerType)) {
-            String propertyName = getPropertyName(m_animatingProperty);
+            String propertyName = getPropertyNameString(m_animatingProperty);
                 
             // Dispatch the event
             RefPtr<Element> element = 0;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to