Bug 96130 - Replace WTF::numberToString() with String::numberToStringECMAScript()
Summary: Replace WTF::numberToString() with String::numberToStringECMAScript()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Patrick R. Gansterer
URL:
Keywords:
Depends on:
Blocks: 96132
  Show dependency treegraph
 
Reported: 2012-09-07 10:22 PDT by Patrick R. Gansterer
Modified: 2012-09-09 17:45 PDT (History)
8 users (show)

See Also:


Attachments
Patch (7.20 KB, patch)
2012-09-07 10:26 PDT, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff
Patch (2.72 KB, patch)
2012-09-09 14:20 PDT, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick R. Gansterer 2012-09-07 10:22:40 PDT
Replace WTF::numberTo*String() with String::number[ToStringECMAScript]()
Comment 1 Patrick R. Gansterer 2012-09-07 10:26:51 PDT
Created attachment 162805 [details]
Patch
Comment 2 Darin Adler 2012-09-07 19:11:02 PDT
Comment on attachment 162805 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=162805&action=review

> Source/JavaScriptCore/ChangeLog:3
> +        Replace WTF::numberTo*String() with String::number[ToStringECMAScript]()

Why?
Comment 3 Benjamin Poulain 2012-09-07 21:18:22 PDT
Comment on attachment 162805 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=162805&action=review

On NumberPrototype and V8DependentRetained, I don't think we can afford one extra function call + the extra branch in String::number().

> Source/WebCore/css/CSSPrimitiveValue.cpp:1028
> -                NumberToStringBuffer buffer;
> -                const char* alphaString = numberToFixedPrecisionString(color.alpha() / 255.0f, 6, buffer, true);
> -                result.append(alphaString, strlen(alphaString));
> +                String alphaString = String::number(color.alpha() / 255.0f);
> +                result.append(alphaString.characters8(), alphaString.length());

This is also a regression.
Previously, we would only allocate NumberToStringBuffer on the stack. With this change, we will allocate a new StringImpl, then copy the content of the buffer to it.

I am also not a fan of relying on the implementation generating a 8bits buffer. It is the case today but that could change in the future.

Given that someone took the time to write the original code is such a contrived way, I assume the performance is important here.

> Source/WebCore/html/parser/HTMLParserIdioms.cpp:90
> -    NumberToStringBuffer buffer;
> -    return String(numberToString(number, buffer));
> +    return String::numberToStringECMAScript(number);

This looks like a good idea. It makes the code simpler and will enjoy https://bugs.webkit.org/show_bug.cgi?id=96132 for free.

> Source/WebCore/platform/Decimal.cpp:685
> -    if (isfinite(doubleValue)) {
> -        NumberToStringBuffer buffer;
> -        return fromString(numberToString(doubleValue, buffer));
> -    }
> +    if (isfinite(doubleValue))
> +        return fromString(String::numberToStringECMAScript(doubleValue));

Ditto.
Comment 4 Patrick R. Gansterer 2012-09-09 14:20:58 PDT
Created attachment 163014 [details]
Patch
Comment 5 WebKit Review Bot 2012-09-09 17:45:35 PDT
Comment on attachment 163014 [details]
Patch

Clearing flags on attachment: 163014

Committed r128008: <http://trac.webkit.org/changeset/128008>
Comment 6 WebKit Review Bot 2012-09-09 17:45:39 PDT
All reviewed patches have been landed.  Closing bug.