2011-02-15 Andreas Kling <kling@webkit.org>

        Reviewed by Darin Adler.

        Optimize Color::serialized()
        https://bugs.webkit.org/show_bug.cgi?id=54452

        Apply the optimizations from CSSPrimitiveValue::cssText() [CSS_RGBCOLOR]
        to Color::serialized() - build the serialized color strings manually
        instead of using String::format().

        * platform/graphics/Color.cpp:
        (WebCore::appendHexNumber):
        (WebCore::Color::serialized):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@78596 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 91e3806e
2011-02-15 Andreas Kling <kling@webkit.org>
Reviewed by Darin Adler.
Optimize Color::serialized()
https://bugs.webkit.org/show_bug.cgi?id=54452
Apply the optimizations from CSSPrimitiveValue::cssText() [CSS_RGBCOLOR]
to Color::serialized() - build the serialized color strings manually
instead of using String::format().
* platform/graphics/Color.cpp:
(WebCore::appendHexNumber):
(WebCore::Color::serialized):
2011-02-15 Jarred Nicholls <jarred@sencha.com>
Reviewed by Alexey Proskuryakov.
......@@ -180,16 +180,49 @@ Color::Color(const char* name)
}
}
static inline void appendHexNumber(UChar* destination, uint8_t number)
{
static const char hexDigits[17] = "0123456789abcdef";
destination[0] = hexDigits[number >> 4];
destination[1] = hexDigits[number & 0xF];
}
String Color::serialized() const
{
if (alpha() == 0xFF)
return String::format("#%02x%02x%02x", red(), green(), blue());
DEFINE_STATIC_LOCAL(const String, commaSpace, (", "));
DEFINE_STATIC_LOCAL(const String, rgbaParen, ("rgba("));
DEFINE_STATIC_LOCAL(const String, zeroPointZero, ("0.0"));
if (!hasAlpha()) {
UChar* characters;
String result = String::createUninitialized(7, characters);
characters[0] = '#';
appendHexNumber(characters + 1, red());
appendHexNumber(characters + 3, green());
appendHexNumber(characters + 5, blue());
return result;
}
Vector<UChar> result;
result.reserveInitialCapacity(28);
append(result, rgbaParen);
appendNumber(result, red());
append(result, commaSpace);
appendNumber(result, green());
append(result, commaSpace);
appendNumber(result, blue());
append(result, commaSpace);
// Match Gecko ("0.0" for zero, 5 decimals for anything else)
if (!alpha())
return String::format("rgba(%u, %u, %u, 0.0)", red(), green(), blue());
append(result, zeroPointZero);
else
append(result, String::format("%.5f", alpha() / 255.0f));
return String::format("rgba(%u, %u, %u, %.5f)", red(), green(), blue(), alpha() / 255.0f);
result.append(')');
return String::adopt(result);
}
String Color::nameForRenderTreeAsText() const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment