Title: [138829] trunk/Source/WebCore
Revision
138829
Author
benja...@webkit.org
Date
2013-01-04 12:23:32 -0800 (Fri, 04 Jan 2013)

Log Message

WebKitCSSTransformValue::customCssText() should always allocate once
https://bugs.webkit.org/show_bug.cgi?id=105445

Reviewed by Alexis Menard.

When converting a WebKitCSSTransformValue to a String representation,
it was typically done with 2 memory allocations due to the string size in StringBuilder.

This patch changes the code to use the String Concatenate operations in order
to create the string at once.

The opening parenthesis is also moved in the prefix name in order to maximize
the range copied with memcopy.

* css/WebKitCSSTransformValue.cpp:
(WebCore::transformValueToCssString): New generic function for boxing values.
(WebCore::WebKitCSSTransformValue::customCssText):
(WebCore::WebKitCSSTransformValue::customSerializeResolvingVariables):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (138828 => 138829)


--- trunk/Source/WebCore/ChangeLog	2013-01-04 20:13:56 UTC (rev 138828)
+++ trunk/Source/WebCore/ChangeLog	2013-01-04 20:23:32 UTC (rev 138829)
@@ -1,3 +1,24 @@
+2013-01-04  Benjamin Poulain  <benja...@webkit.org>
+
+        WebKitCSSTransformValue::customCssText() should always allocate once
+        https://bugs.webkit.org/show_bug.cgi?id=105445
+
+        Reviewed by Alexis Menard.
+
+        When converting a WebKitCSSTransformValue to a String representation,
+        it was typically done with 2 memory allocations due to the string size in StringBuilder.
+
+        This patch changes the code to use the String Concatenate operations in order
+        to create the string at once.
+
+        The opening parenthesis is also moved in the prefix name in order to maximize
+        the range copied with memcopy.
+
+        * css/WebKitCSSTransformValue.cpp:
+        (WebCore::transformValueToCssString): New generic function for boxing values.
+        (WebCore::WebKitCSSTransformValue::customCssText):
+        (WebCore::WebKitCSSTransformValue::customSerializeResolvingVariables):
+
 2013-01-04  James Robinson  <jam...@chromium.org>
 
         [chromium] WebTransformationMatrix shouldn't alias memory for TransformationMatrix

Modified: trunk/Source/WebCore/css/WebKitCSSTransformValue.cpp (138828 => 138829)


--- trunk/Source/WebCore/css/WebKitCSSTransformValue.cpp	2013-01-04 20:13:56 UTC (rev 138828)
+++ trunk/Source/WebCore/css/WebKitCSSTransformValue.cpp	2013-01-04 20:23:32 UTC (rev 138829)
@@ -29,37 +29,45 @@
 #include "CSSValueList.h"
 #include "WebCoreMemoryInstrumentation.h"
 #include <wtf/PassRefPtr.h>
-#include <wtf/text/StringBuilder.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
 // These names must be kept in sync with TransformOperationType.
-const char* const transformName[] = {
-     0,
-     "translate",
-     "translateX",
-     "translateY",
-     "rotate",
-     "scale",
-     "scaleX",
-     "scaleY",
-     "skew",
-     "skewX",
-     "skewY",
-     "matrix",
-     "translateZ",
-     "translate3d",
-     "rotateX",
-     "rotateY",
-     "rotateZ",
-     "rotate3d",
-     "scaleZ",
-     "scale3d",
-     "perspective",
-     "matrix3d"
+const char* const transformNamePrefixes[] = {
+    0,
+    "translate(",
+    "translateX(",
+    "translateY(",
+    "rotate(",
+    "scale(",
+    "scaleX(",
+    "scaleY(",
+    "skew(",
+    "skewX(",
+    "skewY(",
+    "matrix(",
+    "translateZ(",
+    "translate3d(",
+    "rotateX(",
+    "rotateY(",
+    "rotateZ(",
+    "rotate3d(",
+    "scaleZ(",
+    "scale3d(",
+    "perspective(",
+    "matrix3d("
 };
 
+static inline String transformValueToCssString(WebKitCSSTransformValue::TransformOperationType operation, const String& value)
+{
+    if (operation != WebKitCSSTransformValue::UnknownTransformOperation) {
+        ASSERT(static_cast<size_t>(operation) < WTF_ARRAY_LENGTH(transformNamePrefixes));
+        return makeString(transformNamePrefixes[operation], value, ')');
+    }
+    return String();
+}
+
 WebKitCSSTransformValue::WebKitCSSTransformValue(TransformOperationType op)
     : CSSValueList(WebKitCSSTransformClass, CommaSeparator)
     , m_type(op)
@@ -68,29 +76,13 @@
 
 String WebKitCSSTransformValue::customCssText() const
 {
-    StringBuilder result;
-    if (m_type != UnknownTransformOperation) {
-        ASSERT(static_cast<size_t>(m_type) < WTF_ARRAY_LENGTH(transformName));
-        result.append(transformName[m_type]);
-        result.append('(');
-        result.append(CSSValueList::customCssText());
-        result.append(')');
-    }
-    return result.toString();
+    return transformValueToCssString(m_type, CSSValueList::customCssText());
 }
 
 #if ENABLE(CSS_VARIABLES)
 String WebKitCSSTransformValue::customSerializeResolvingVariables(const HashMap<AtomicString, String>& variables) const
 {
-    StringBuilder result;
-    if (m_type != UnknownTransformOperation) {
-        ASSERT(static_cast<size_t>(m_type) < WTF_ARRAY_LENGTH(transformName));
-        result.append(transformName[m_type]);
-        result.append('(');
-        result.append(CSSValueList::customSerializeResolvingVariables(variables));
-        result.append(')');
-    }
-    return result.toString();
+    return transformValueToCssString(m_type, CSSValueList::customSerializeResolvingVariables(variables));
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to