Title: [126186] trunk/Source/WebCore
Revision
126186
Author
[email protected]
Date
2012-08-21 14:23:12 -0700 (Tue, 21 Aug 2012)

Log Message

Create CSS color output string on 8 bits
https://bugs.webkit.org/show_bug.cgi?id=94625

Patch by Benjamin Poulain <[email protected]> on 2012-08-21
Reviewed by Andreas Kling.

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::customCssText):
Previously, the output string for a CSS color was computed on 16 bits.
This was mainly forced by the use of String::number().

Since the double to string conversion is done on 8bits anyway, I changed
the code to use dtoa's numberToFixedPrecisionString directly instead of
String::number().
All the other parts were already on 8bits.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (126185 => 126186)


--- trunk/Source/WebCore/ChangeLog	2012-08-21 21:21:39 UTC (rev 126185)
+++ trunk/Source/WebCore/ChangeLog	2012-08-21 21:23:12 UTC (rev 126186)
@@ -1,3 +1,20 @@
+2012-08-21  Benjamin Poulain  <[email protected]>
+
+        Create CSS color output string on 8 bits
+        https://bugs.webkit.org/show_bug.cgi?id=94625
+
+        Reviewed by Andreas Kling.
+
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::CSSPrimitiveValue::customCssText):
+        Previously, the output string for a CSS color was computed on 16 bits.
+        This was mainly forced by the use of String::number().
+
+        Since the double to string conversion is done on 8bits anyway, I changed
+        the code to use dtoa's numberToFixedPrecisionString directly instead of
+        String::number().
+        All the other parts were already on 8bits.
+
 2012-08-21  Martin Robinson  <[email protected]>
 
         [GTK] Using a native window for the WebView breaks GtkOverlay

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (126185 => 126186)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2012-08-21 21:21:39 UTC (rev 126185)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2012-08-21 21:23:12 UTC (rev 126186)
@@ -1,6 +1,6 @@
 /*
  * (C) 1999-2003 Lars Knoll ([email protected])
- * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -1001,32 +1001,32 @@
         }
         case CSS_RGBCOLOR:
         case CSS_PARSER_HEXCOLOR: {
-            DEFINE_STATIC_LOCAL(const String, commaSpace, (", "));
-            DEFINE_STATIC_LOCAL(const String, rgbParen, ("rgb("));
-            DEFINE_STATIC_LOCAL(const String, rgbaParen, ("rgba("));
-
             RGBA32 rgbColor = m_value.rgbcolor;
             if (m_primitiveUnitType == CSS_PARSER_HEXCOLOR)
                 Color::parseHexColor(m_value.string, rgbColor);
             Color color(rgbColor);
 
-            Vector<UChar> result;
+            Vector<LChar> result;
             result.reserveInitialCapacity(32);
-            if (color.hasAlpha())
-                append(result, rgbaParen);
+            bool colorHasAlpha = color.hasAlpha();
+            if (colorHasAlpha)
+                result.append("rgba(", 5);
             else
-                append(result, rgbParen);
+                result.append("rgb(", 4);
 
             appendNumber(result, static_cast<unsigned char>(color.red()));
-            append(result, commaSpace);
+            result.append(", ", 2);
 
             appendNumber(result, static_cast<unsigned char>(color.green()));
-            append(result, commaSpace);
+            result.append(", ", 2);
 
             appendNumber(result, static_cast<unsigned char>(color.blue()));
-            if (color.hasAlpha()) {
-                append(result, commaSpace);
-                append(result, String::number(color.alpha() / 255.0f));
+            if (colorHasAlpha) {
+                result.append(", ", 2);
+
+                NumberToStringBuffer buffer;
+                const char* alphaString = numberToFixedPrecisionString(color.alpha() / 255.0f, 6, buffer, true);
+                result.append(alphaString, strlen(alphaString));
             }
 
             result.append(')');
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to