Use StringBuilder in WebKitCSSTransformValue::customCssText() to allow code reuse...
authormacpherson@chromium.org <macpherson@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 May 2012 01:53:17 +0000 (01:53 +0000)
committermacpherson@chromium.org <macpherson@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 May 2012 01:53:17 +0000 (01:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=87462

Reviewed by Dimitri Glazkov.

Factor out strings into a const char* array, and use a StringBuilder instead of String concatenation.
This will allow future code to re-use the array of transform names, and StringBuilder is generally faster.

Covered by existing CSS transform tests.

* css/WebKitCSSTransformValue.cpp:
(WebCore):
(WebCore::WebKitCSSTransformValue::customCssText):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@118639 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/WebKitCSSTransformValue.cpp

index 212e053..c556224 100644 (file)
@@ -1,3 +1,19 @@
+2012-05-27  Luke Macpherson  <macpherson@chromium.org>
+
+        Use StringBuilder in WebKitCSSTransformValue::customCssText() to allow code reuse with CSS Variables.
+        https://bugs.webkit.org/show_bug.cgi?id=87462
+
+        Reviewed by Dimitri Glazkov.
+
+        Factor out strings into a const char* array, and use a StringBuilder instead of String concatenation.
+        This will allow future code to re-use the array of transform names, and StringBuilder is generally faster.
+
+        Covered by existing CSS transform tests.
+
+        * css/WebKitCSSTransformValue.cpp:
+        (WebCore):
+        (WebCore::WebKitCSSTransformValue::customCssText):
+
 2012-05-27  Arvid Nilsson  <anilsson@rim.com>
 
         [BlackBerry] Update color for tap highlight and selection
index dfdd71e..8580226 100644 (file)
 #include "CSSValueList.h"
 #include "PlatformString.h"
 #include <wtf/PassRefPtr.h>
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
+const int transformNameSize = 22;
+const char* const transformName[transformNameSize] = {
+     "",
+     "translate",
+     "translateX",
+     "translateY",
+     "rotate",
+     "scale",
+     "scaleX",
+     "scaleY",
+     "skew",
+     "skewX",
+     "skewY",
+     "matrix",
+     "translateZ",
+     "translate3d",
+     "rotateX",
+     "rotateY",
+     "rotateZ",
+     "rotate3d",
+     "scaleZ",
+     "scale3d",
+     "perspective",
+     "matrix3d"
+};
+
 WebKitCSSTransformValue::WebKitCSSTransformValue(TransformOperationType op)
     : CSSValueList(WebKitCSSTransformClass, CommaSeparator)
     , m_type(op)
@@ -40,79 +67,15 @@ WebKitCSSTransformValue::WebKitCSSTransformValue(TransformOperationType op)
 
 String WebKitCSSTransformValue::customCssText() const
 {
-    String result;
-    switch (m_type) {
-        case TranslateTransformOperation:
-            result += "translate(";
-            break;
-        case TranslateXTransformOperation:
-            result += "translateX(";
-            break;
-        case TranslateYTransformOperation:
-            result += "translateY(";
-            break;
-        case RotateTransformOperation:
-            result += "rotate(";
-            break;
-        case ScaleTransformOperation:
-            result += "scale(";
-            break;
-        case ScaleXTransformOperation:
-            result += "scaleX(";
-            break;
-        case ScaleYTransformOperation:
-            result += "scaleY(";
-            break;
-        case SkewTransformOperation:
-            result += "skew(";
-            break;
-        case SkewXTransformOperation:
-            result += "skewX(";
-            break;
-        case SkewYTransformOperation:
-            result += "skewY(";
-            break;
-        case MatrixTransformOperation:
-            result += "matrix(";
-            break;
-        case TranslateZTransformOperation:
-            result += "translateZ(";
-            break;
-        case Translate3DTransformOperation:
-            result += "translate3d(";
-            break;
-        case RotateXTransformOperation:
-            result += "rotateX(";
-            break;
-        case RotateYTransformOperation:
-            result += "rotateY(";
-            break;
-        case RotateZTransformOperation:
-            result += "rotateZ(";
-            break;
-        case Rotate3DTransformOperation:
-            result += "rotate3d(";
-            break;
-        case ScaleZTransformOperation:
-            result += "scaleZ(";
-            break;
-        case Scale3DTransformOperation:
-            result += "scale3d(";
-            break;
-        case PerspectiveTransformOperation:
-            result += "perspective(";
-            break;
-        case Matrix3DTransformOperation:
-            result += "matrix3d(";
-            break;
-        default:
-            break;
+    StringBuilder result;
+    if (m_type != UnknownTransformOperation) {
+        ASSERT(m_type < transformNameSize);
+        result.append(transformName[m_type]);
+        result.append('(');
+        result.append(CSSValueList::customCssText());
+        result.append(')');
     }
-
-    result += CSSValueList::customCssText();
-
-    result += ")";
-    return result;
+    return result.toString();
 }
 
 WebKitCSSTransformValue::WebKitCSSTransformValue(const WebKitCSSTransformValue& cloneFrom)