Changeset 254514 in webkit


Ignore:
Timestamp:
Jan 14, 2020 9:16:03 AM (4 years ago)
Author:
Darin Adler
Message:

Use even more "shortest form" formatting, and less "fixed precision" and "fixed width"
https://bugs.webkit.org/show_bug.cgi?id=198918

Reviewed by Sam Weinig.

Source/JavaScriptCore:

  • API/tests/ExecutionTimeLimitTest.cpp:

(testExecutionTimeLimit): Rewrote the string creation code to use makeString instead
of StringBuilder and no longer use any fixed precision.

  • runtime/Options.cpp:

(JSC::OptionReader::Option::dump const): Dump doubles with shortest form instead of
fixed precision.

Source/WebCore:

The places left untouched are the ones where changing behavior has some kind of unwanted
observable effect for one of two reasons. Otherwise, switched almost all call sites.

1) Substantial number of test results that depend on the current behavior.

2) Poor rounding resulting in conversion from float to double and back (or similar) that

results in values with tiny fractional residue like "6.000001".

  • accessibility/AccessibilityNodeObject.cpp:

(WebCore::AccessibilityNodeObject::changeValueByStep): Use shortest instead of fixed.
(WebCore::AccessibilityNodeObject::changeValueByPercent): Ditto.

  • css/CSSAspectRatioValue.cpp:

(WebCore::CSSAspectRatioValue::customCSSText const): Ditto.

  • css/CSSFontVariationValue.cpp:

(WebCore::CSSFontVariationValue::customCSSText const): Ditto. Also use makeString instead of
StringBuilder for better efficiency.

  • css/CSSGradientValue.cpp:

(WebCore::appendGradientStops): Ditto.

  • css/CSSKeyframeRule.cpp:

(WebCore::StyleRuleKeyframe::keyText const): Ditto.

  • css/CSSTimingFunctionValue.cpp:

(WebCore::CSSCubicBezierTimingFunctionValue::customCSSText const): Ditto.

  • css/MediaQueryEvaluator.cpp:

(WebCore::aspectRatioValueAsString): Ditto.

  • css/TransformFunctions.h: Removed unnneeded forward declarations.
  • css/parser/CSSParserToken.cpp:

(WebCore::CSSParserToken::serialize const): Use shortest instead of fixed.

  • html/HTMLImageElement.cpp:

(WebCore::HTMLImageElement::completeURLsInAttributeValue const): Ditto.

  • html/track/VTTCue.cpp:

(WebCore::VTTCueBox::applyCSSProperties): Use shortest instead of fixed.
Also wrote a FIXME abot this strange code that uses "calc()" to do math on two numbers,
math that could instead be done by the code converting the numbers to a style string.

  • inspector/InspectorOverlay.cpp:

(WebCore::InspectorOverlay::drawRulers): Use shortest instead of fixed.

  • page/CaptionUserPreferencesMediaAF.cpp:

(WebCore::CaptionUserPreferencesMediaAF::windowRoundedCornerRadiusCSS const): Ditto.

  • page/scrolling/AxisScrollSnapOffsets.cpp:

(WebCore::snapOffsetsToString): Ditto.
(WebCore::snapOffsetRangesToString): Ditto.
(WebCore::snapPortOrAreaToString): Ditto.

  • platform/graphics/Color.cpp:

(WebCore::decimalDigit): Added.
(WebCore::serializedFractionDigitsForFractionalAlphaValue): Added.
(WebCore::Color::cssText const): Rewrote to generate the same results using
makeString rather than StringBuilder, and integer math rather than converting from
integer to floating point and then doing floating point math.

  • platform/graphics/ExtendedColor.cpp:

(WebCore::ExtendedColor::cssText const): Use shortest instead of fixed.

  • rendering/RenderLayerCompositor.cpp:

(WebCore::RenderLayerCompositor::logLayerInfo): Ditto.

  • svg/SVGAngleValue.cpp:

(WebCore::SVGAngleValue::valueAsString const): Ditto.

  • svg/SVGLengthList.h: Added now-needed include of StringBuilder.h.
  • svg/SVGLengthValue.cpp:

(WebCore::SVGLengthValue::valueAsString const): Use shortest instead of fixed.

  • svg/SVGNumberList.h: Ditto.
  • svg/SVGPathStringBuilder.cpp:

(WebCore::appendFlag): Use multiple-argument append for better efficiency.
(WebCore::appendNumber): Added a comment about why we can't yet convert this to use
shortest instead of fixed: code that parses floats but then creates a CG path
that stores things as double and does math as double then converts back to float
results in float values that didn't round trip well and have fractions. This is
smoothed away (hidden) by using fixed precision to conver them to strings.
(WebCore::appendPoint): Call appendNumber to cut down on repeated code.

  • svg/SVGPointList.h: Use shortest instead of fixed.
  • svg/SVGTransformValue.h:

(WebCore::SVGTransformValue::prefixForTransfromType): Return a string literal
instead of a WTF::String to avoid creating and destroying an object each time.
(WebCore::SVGTransformValue::appendFixedPrecisionNumbers): Added a comment explaining
why we need to continue to use fixed precision here. Same issue with CGAffineTransform
using double as we have with CGPath above.

  • svg/properties/SVGPropertyTraits.h:

(WebCore::SVGPropertyTraits<float>::toString): Use shortest instead of fixed.
(WebCore::SVGPropertyTraits<FloatPoint>::toString): Ditto.
(WebCore::SVGPropertyTraits<FloatRect>::toString): Ditto.

  • testing/Internals.cpp:

(WebCore::Internals::dumpMarkerRects): Added a comment explaining why we have to use
fixed precision here. There are many test results that we would need to update.
(WebCore::Internals::configurationForViewport): Ditto.
(WebCore::Internals::getCurrentCursorInfo): Use shortest instead of fixed.

  • xml/XPathValue.cpp:

(WebCore::XPath::Value::toString const): Ditto.

Source/WebKit:

  • NetworkProcess/cache/NetworkCache.cpp:

(WebKit::NetworkCache::Cache::dumpContentsToFile): Use shortest instead of fixed.
Also use makeString instead of StringBuilder.

  • NetworkProcess/cache/NetworkCacheEntry.cpp:

(WebKit::NetworkCache::Entry::asJSON const): Use shortest instead of fixed.
Also use multiple-argument append on StringBuilder to make the function shorter
and easier to read.

  • Shared/Gamepad/GamepadData.cpp:

(WebKit::GamepadData::loggingString const): Ditto.

  • UIProcess/ViewGestureController.cpp:

(WebKit::ViewGestureController::SnapshotRemovalTracker::startWatchdog):
Use shortest instead of fixed.

Source/WTF:

  • wtf/Logger.h:

(WTF::LogArgument::toString): Log floating point numbers as shortest form instead of fixed precision.

  • wtf/MediaTime.cpp:

(WTF::MediaTime::toString const): Convert time to string as shortest form instead of fixed precision.
Also use multiple-argument append for great simplicity and clarity.

LayoutTests:

  • platform/mac/svg/dom/length-list-parser-expected.png: Removed. Not sure how many other pixel

results we have like this, but this included an ancient style Aqua scrollbar so hasn't matched
anything for years and would clearly not have any value for regression testing.

  • svg/dom/length-list-parser-expected.txt: Updated to expect logging of a 7 digit length as an

integer rather than rounded as "d.ddddd+6".

Location:
trunk
Files:
1 deleted
41 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r254513 r254514  
     12020-01-13  Darin Adler  <darin@apple.com>
     2
     3        Use even more "shortest form" formatting, and less "fixed precision" and "fixed width"
     4        https://bugs.webkit.org/show_bug.cgi?id=198918
     5
     6        Reviewed by Sam Weinig.
     7
     8        * platform/mac/svg/dom/length-list-parser-expected.png: Removed. Not sure how many other pixel
     9        results we have like this, but this included an ancient style Aqua scrollbar so hasn't matched
     10        anything for years and would clearly not have any value for regression testing.
     11
     12        * svg/dom/length-list-parser-expected.txt: Updated to expect logging of a 7 digit length as an
     13        integer rather than rounded as "d.ddddd+6".
     14
    1152020-01-14  Chris Lord  <clord@igalia.com>
    216
  • trunk/LayoutTests/svg/dom/length-list-parser-expected.txt

    r101056 r254514  
    55
    66Parsed as 1 length(s) [ 8.847 ]: 8.847
    7 Parsed as 1 length(s) [ 8.62569e+6 ]: 8625686 3.0-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, 90,e4997..,782-4326e.   -0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013e,+e9     e 4829.,063721-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001.-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e6 072
     7Parsed as 1 length(s) [ 8625686 ]: 8625686 3.0-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, 90,e4997..,782-4326e.      -0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013e,+e9     e 4829.,063721-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001.-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e6 072
    88Parsed as 1 length(s) [ 61822 ]: 61822,15-00.166.7
    99Parsed as 2 length(s) [ 2, 0.5 ]: 2     .5,658-7 e ,8477553
  • trunk/Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.cpp

    r254480 r254514  
    199199            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
    200200
    201             StringBuilder scriptBuilder;
    202             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
    203             scriptBuilder.append(FormattedNumber::fixedPrecision(timeAfterWatchdogShouldHaveFired.seconds()));
    204             scriptBuilder.appendLiteral(") break; } } foo();");
    205 
    206             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
     201            CString scriptText = makeString(
     202                "function foo() {"
     203                    "var startTime = currentCPUTime();"
     204                    "while (true) {"
     205                        "for (var i = 0; i < 1000; i++);"
     206                        "if (currentCPUTime() - startTime > ", timeAfterWatchdogShouldHaveFired.seconds(), ") break;"
     207                    "}"
     208                "}"
     209                "foo();"
     210            ).utf8();
     211
     212            JSStringRef script = JSStringCreateWithUTF8CString(scriptText.data());
    207213            exception = nullptr;
    208214            shouldTerminateCallbackWasCalled = false;
     
    236242            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
    237243
    238             StringBuilder scriptBuilder;
    239             scriptBuilder.appendLiteral("var startTime = currentCPUTime();"
    240                                  "function recurse(i) {"
    241                                      "'use strict';"
    242                                      "if (i % 1000 === 0) {"
    243                                         "if (currentCPUTime() - startTime >");
    244             scriptBuilder.append(FormattedNumber::fixedPrecision(timeAfterWatchdogShouldHaveFired.seconds()));
    245             scriptBuilder.appendLiteral("       ) { return; }");
    246             scriptBuilder.appendLiteral("    }");
    247             scriptBuilder.appendLiteral("    return recurse(i + 1); }");
    248             scriptBuilder.appendLiteral("recurse(0);");
    249 
    250             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
     244            CString scriptText = makeString(
     245                "var startTime = currentCPUTime();"
     246                "function recurse(i) {"
     247                    "'use strict';"
     248                    "if (i % 1000 === 0) {"
     249                        "if (currentCPUTime() - startTime >", timeAfterWatchdogShouldHaveFired.seconds(), ") { return; }"
     250                    "}"
     251                "return recurse(i + 1); }"
     252                "recurse(0);"
     253            ).utf8();
     254
     255            JSStringRef script = JSStringCreateWithUTF8CString(scriptText.data());
    251256            exception = nullptr;
    252257            shouldTerminateCallbackWasCalled = false;
     
    280285            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
    281286           
    282             StringBuilder scriptBuilder;
    283             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); try { while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
    284             scriptBuilder.append(FormattedNumber::fixedPrecision(timeAfterWatchdogShouldHaveFired.seconds()));
    285             scriptBuilder.appendLiteral(") break; } } catch(e) { } } foo();");
    286 
    287             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
     287            CString scriptText = makeString(
     288                "function foo() {"
     289                    "var startTime = currentCPUTime();"
     290                    "try {"
     291                        "while (true) {"
     292                            "for (var i = 0; i < 1000; i++);"
     293                                "if (currentCPUTime() - startTime > ", timeAfterWatchdogShouldHaveFired.seconds(), ") break;"
     294                        "}"
     295                    "} catch(e) { }"
     296                "}"
     297                "foo();"
     298            ).utf8();
     299
     300            JSStringRef script = JSStringCreateWithUTF8CString(scriptText.data());
    288301            exception = nullptr;
    289302            shouldTerminateCallbackWasCalled = false;
     
    319332            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
    320333           
    321             StringBuilder scriptBuilder;
    322             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
    323             scriptBuilder.append(FormattedNumber::fixedPrecision(timeAfterWatchdogShouldHaveFired.seconds()));
    324             scriptBuilder.appendLiteral(") break; } } foo();");
    325            
    326             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
     334            CString scriptText = makeString(
     335                "function foo() {"
     336                    "var startTime = currentCPUTime();"
     337                    "while (true) {"
     338                        "for (var i = 0; i < 1000; i++);"
     339                            "if (currentCPUTime() - startTime > ", timeAfterWatchdogShouldHaveFired.seconds(), ") break;"
     340                    "}"
     341                "}"
     342                "foo();"
     343            ).utf8();
     344           
     345            JSStringRef script = JSStringCreateWithUTF8CString(scriptText.data());
    327346            exception = nullptr;
    328347            shouldTerminateCallbackWasCalled = false;
     
    358377            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
    359378           
    360             StringBuilder scriptBuilder;
    361             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
    362             scriptBuilder.append(FormattedNumber::fixedPrecision(timeAfterWatchdogShouldHaveFired.seconds()));
    363             scriptBuilder.appendLiteral(") break; } } foo();");
    364 
    365             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
     379            CString scriptText = makeString(
     380                "function foo() {"
     381                    "var startTime = currentCPUTime();"
     382                    "while (true) {"
     383                        "for (var i = 0; i < 1000; i++);"
     384                            "if (currentCPUTime() - startTime > ", timeAfterWatchdogShouldHaveFired.seconds(), ") break;"
     385                    "}"
     386                "}"
     387                "foo();"
     388            ).utf8();
     389
     390            JSStringRef script = JSStringCreateWithUTF8CString(scriptText.data());
    366391            exception = nullptr;
    367392            cancelTerminateCallbackWasCalled = false;
     
    397422            Seconds maxBusyLoopTime = 750_ms + tierAdjustment;
    398423
    399             StringBuilder scriptBuilder;
    400             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
    401             scriptBuilder.append(FormattedNumber::fixedPrecision(maxBusyLoopTime.seconds())); // in seconds.
    402             scriptBuilder.appendLiteral(") break; } } foo();");
    403 
    404             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
     424            CString scriptText = makeString(
     425                "function foo() {"
     426                    "var startTime = currentCPUTime();"
     427                    "while (true) {"
     428                        "for (var i = 0; i < 1000; i++);"
     429                            "if (currentCPUTime() - startTime > ", maxBusyLoopTime.seconds(), ") break;"
     430                    "}"
     431                "}"
     432                "foo();"
     433            ).utf8();
     434
     435            JSStringRef script = JSStringCreateWithUTF8CString(scriptText.data());
    405436            exception = nullptr;
    406437            extendTerminateCallbackCalled = 0;
     
    440471            Seconds timeAfterWatchdogShouldHaveFired = 300_ms + tierAdjustment;
    441472
    442             StringBuilder scriptBuilder;
    443             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
    444             scriptBuilder.append(FormattedNumber::fixedPrecision(timeAfterWatchdogShouldHaveFired.seconds()));
    445             scriptBuilder.appendLiteral(") break; } } foo();");
    446 
    447             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
     473            CString scriptText = makeString(
     474                "function foo() {"
     475                    "var startTime = currentCPUTime();"
     476                    "while (true) {"
     477                        "for (var i = 0; i < 1000; i++);"
     478                            "if (currentCPUTime() - startTime > ", timeAfterWatchdogShouldHaveFired.seconds(), ") break;"
     479                    "}"
     480                "}"
     481                "foo();"
     482            ).utf8();
     483
     484            JSStringRef script = JSStringCreateWithUTF8CString(scriptText.data());
    448485            exception = nullptr;
    449486            dispatchTerminateCallbackCalled = false;
  • trunk/Source/JavaScriptCore/ChangeLog

    r254500 r254514  
     12020-01-13  Darin Adler  <darin@apple.com>
     2
     3        Use even more "shortest form" formatting, and less "fixed precision" and "fixed width"
     4        https://bugs.webkit.org/show_bug.cgi?id=198918
     5
     6        Reviewed by Sam Weinig.
     7
     8        * API/tests/ExecutionTimeLimitTest.cpp:
     9        (testExecutionTimeLimit): Rewrote the string creation code to use makeString instead
     10        of StringBuilder and no longer use any fixed precision.
     11
     12        * runtime/Options.cpp:
     13        (JSC::OptionReader::Option::dump const): Dump doubles with shortest form instead of
     14        fixed precision.
     15
    1162020-01-14  David Kilzer  <ddkilzer@apple.com>
    217
  • trunk/Source/JavaScriptCore/runtime/Options.cpp

    r254480 r254514  
    10061006        break;
    10071007    case Options::Type::Double:
    1008         builder.append(FormattedNumber::fixedPrecision(m_double));
     1008        builder.append(m_double);
    10091009        break;
    10101010    case Options::Type::Int32:
  • trunk/Source/WTF/ChangeLog

    r254509 r254514  
     12020-01-13  Darin Adler  <darin@apple.com>
     2
     3        Use even more "shortest form" formatting, and less "fixed precision" and "fixed width"
     4        https://bugs.webkit.org/show_bug.cgi?id=198918
     5
     6        Reviewed by Sam Weinig.
     7
     8        * wtf/Logger.h:
     9        (WTF::LogArgument::toString): Log floating point numbers as shortest form instead of fixed precision.
     10
     11        * wtf/MediaTime.cpp:
     12        (WTF::MediaTime::toString const): Convert time to string as shortest form instead of fixed precision.
     13        Also use multiple-argument append for great simplicity and clarity.
     14
    1152020-01-14  Alicia Boya García  <aboya@igalia.com>
    216
  • trunk/Source/WTF/wtf/Logger.h

    r253900 r254514  
    4242    template<typename U = T> static typename std::enable_if<std::is_same<U, long long>::value, String>::type toString(long long argument) { return String::number(argument); }
    4343    template<typename U = T> static typename std::enable_if<std::is_enum<U>::value, String>::type toString(U argument) { return String::number(static_cast<typename std::underlying_type<U>::type>(argument)); }
    44     template<typename U = T> static typename std::enable_if<std::is_same<U, float>::value, String>::type toString(float argument) { return String::numberToStringFixedPrecision(argument); }
    45     template<typename U = T> static typename std::enable_if<std::is_same<U, double>::value, String>::type toString(double argument) { return String::numberToStringFixedPrecision(argument); }
     44    template<typename U = T> static typename std::enable_if<std::is_same<U, float>::value, String>::type toString(float argument) { return String::number(argument); }
     45    template<typename U = T> static typename std::enable_if<std::is_same<U, double>::value, String>::type toString(double argument) { return String::number(argument); }
    4646    template<typename U = T> static typename std::enable_if<std::is_same<typename std::remove_reference<U>::type, AtomString>::value, String>::type toString(const AtomString& argument) { return argument.string(); }
    4747    template<typename U = T> static typename std::enable_if<std::is_same<typename std::remove_reference<U>::type, String>::value, String>::type toString(String argument) { return argument; }
  • trunk/Source/WTF/wtf/MediaTime.cpp

    r254509 r254514  
    567567{
    568568    StringBuilder builder;
    569 
    570569    builder.append('{');
    571     if (!hasDoubleValue()) {
    572         builder.appendNumber(m_timeValue);
    573         builder.append('/');
    574         builder.appendNumber(m_timeScale);
    575         builder.appendLiteral(" = ");
    576     }
    577     builder.append(FormattedNumber::fixedPrecision(toDouble()));
     570    if (!hasDoubleValue())
     571        builder.append(m_timeValue, '/', m_timeScale, " = ");
     572    builder.append(toDouble());
    578573    if (isInvalid())
    579574        builder.appendLiteral(", invalid");
  • trunk/Source/WebCore/ChangeLog

    r254512 r254514  
     12020-01-13  Darin Adler  <darin@apple.com>
     2
     3        Use even more "shortest form" formatting, and less "fixed precision" and "fixed width"
     4        https://bugs.webkit.org/show_bug.cgi?id=198918
     5
     6        Reviewed by Sam Weinig.
     7
     8        The places left untouched are the ones where changing behavior has some kind of unwanted
     9        observable effect for one of two reasons. Otherwise, switched almost all call sites.
     10
     11        1) Substantial number of test results that depend on the current behavior.
     12
     13        2) Poor rounding resulting in conversion from float to double and back (or similar) that
     14           results in values with tiny fractional residue like "6.000001".
     15
     16        * accessibility/AccessibilityNodeObject.cpp:
     17        (WebCore::AccessibilityNodeObject::changeValueByStep): Use shortest instead of fixed.
     18        (WebCore::AccessibilityNodeObject::changeValueByPercent): Ditto.
     19        * css/CSSAspectRatioValue.cpp:
     20        (WebCore::CSSAspectRatioValue::customCSSText const): Ditto.
     21        * css/CSSFontVariationValue.cpp:
     22        (WebCore::CSSFontVariationValue::customCSSText const): Ditto. Also use makeString instead of
     23        StringBuilder for better efficiency.
     24        * css/CSSGradientValue.cpp:
     25        (WebCore::appendGradientStops): Ditto.
     26        * css/CSSKeyframeRule.cpp:
     27        (WebCore::StyleRuleKeyframe::keyText const): Ditto.
     28        * css/CSSTimingFunctionValue.cpp:
     29        (WebCore::CSSCubicBezierTimingFunctionValue::customCSSText const): Ditto.
     30        * css/MediaQueryEvaluator.cpp:
     31        (WebCore::aspectRatioValueAsString): Ditto.
     32
     33        * css/TransformFunctions.h: Removed unnneeded forward declarations.
     34
     35        * css/parser/CSSParserToken.cpp:
     36        (WebCore::CSSParserToken::serialize const): Use shortest instead of fixed.
     37        * html/HTMLImageElement.cpp:
     38        (WebCore::HTMLImageElement::completeURLsInAttributeValue const): Ditto.
     39
     40        * html/track/VTTCue.cpp:
     41        (WebCore::VTTCueBox::applyCSSProperties): Use shortest instead of fixed.
     42        Also wrote a FIXME abot this strange code that uses "calc()" to do math on two numbers,
     43        math that could instead be done by the code converting the numbers to a style string.
     44
     45        * inspector/InspectorOverlay.cpp:
     46        (WebCore::InspectorOverlay::drawRulers): Use shortest instead of fixed.
     47        * page/CaptionUserPreferencesMediaAF.cpp:
     48        (WebCore::CaptionUserPreferencesMediaAF::windowRoundedCornerRadiusCSS const): Ditto.
     49        * page/scrolling/AxisScrollSnapOffsets.cpp:
     50        (WebCore::snapOffsetsToString): Ditto.
     51        (WebCore::snapOffsetRangesToString): Ditto.
     52        (WebCore::snapPortOrAreaToString): Ditto.
     53
     54        * platform/graphics/Color.cpp:
     55        (WebCore::decimalDigit): Added.
     56        (WebCore::serializedFractionDigitsForFractionalAlphaValue): Added.
     57        (WebCore::Color::cssText const): Rewrote to generate the same results using
     58        makeString rather than StringBuilder, and integer math rather than converting from
     59        integer to floating point and then doing floating point math.
     60
     61        * platform/graphics/ExtendedColor.cpp:
     62        (WebCore::ExtendedColor::cssText const): Use shortest instead of fixed.
     63        * rendering/RenderLayerCompositor.cpp:
     64        (WebCore::RenderLayerCompositor::logLayerInfo): Ditto.
     65        * svg/SVGAngleValue.cpp:
     66        (WebCore::SVGAngleValue::valueAsString const): Ditto.
     67
     68        * svg/SVGLengthList.h: Added now-needed include of StringBuilder.h.
     69
     70        * svg/SVGLengthValue.cpp:
     71        (WebCore::SVGLengthValue::valueAsString const): Use shortest instead of fixed.
     72        * svg/SVGNumberList.h: Ditto.
     73
     74        * svg/SVGPathStringBuilder.cpp:
     75        (WebCore::appendFlag): Use multiple-argument append for better efficiency.
     76        (WebCore::appendNumber): Added a comment about why we can't yet convert this to use
     77        shortest instead of fixed: code that parses floats but then creates a CG path
     78        that stores things as double and does math as double then converts back to float
     79        results in float values that didn't round trip well and have fractions. This is
     80        smoothed away (hidden) by using fixed precision to conver them to strings.
     81        (WebCore::appendPoint): Call appendNumber to cut down on repeated code.
     82
     83        * svg/SVGPointList.h: Use shortest instead of fixed.
     84
     85        * svg/SVGTransformValue.h:
     86        (WebCore::SVGTransformValue::prefixForTransfromType): Return a string literal
     87        instead of a WTF::String to avoid creating and destroying an object each time.
     88        (WebCore::SVGTransformValue::appendFixedPrecisionNumbers): Added a comment explaining
     89        why we need to continue to use fixed precision here. Same issue with CGAffineTransform
     90        using double as we have with CGPath above.
     91
     92        * svg/properties/SVGPropertyTraits.h:
     93        (WebCore::SVGPropertyTraits<float>::toString): Use shortest instead of fixed.
     94        (WebCore::SVGPropertyTraits<FloatPoint>::toString): Ditto.
     95        (WebCore::SVGPropertyTraits<FloatRect>::toString): Ditto.
     96
     97        * testing/Internals.cpp:
     98        (WebCore::Internals::dumpMarkerRects): Added a comment explaining why we have to use
     99        fixed precision here. There are many test results that we would need to update.
     100        (WebCore::Internals::configurationForViewport): Ditto.
     101        (WebCore::Internals::getCurrentCursorInfo): Use shortest instead of fixed.
     102        * xml/XPathValue.cpp:
     103        (WebCore::XPath::Value::toString const): Ditto.
     104
    11052020-01-14  Peng Liu  <peng.liu6@apple.com>
    2106
  • trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp

    r253261 r254514  
    11051105    value += increase ? step : -step;
    11061106
    1107     setValue(String::numberToStringFixedPrecision(value));
     1107    setValue(String::number(value));
    11081108
    11091109    auto objectCache = axObjectCache();
     
    11231123
    11241124    value += step;
    1125     setValue(String::numberToStringFixedPrecision(value));
     1125    setValue(String::number(value));
    11261126
    11271127    auto objectCache = axObjectCache();
  • trunk/Source/WebCore/css/CSSAspectRatioValue.cpp

    r241244 r254514  
    3636String CSSAspectRatioValue::customCSSText() const
    3737{
    38     return makeString(FormattedNumber::fixedPrecision(m_numeratorValue), '/', FormattedNumber::fixedPrecision(m_denominatorValue));
     38    return makeString(m_numeratorValue, '/', m_denominatorValue);
    3939}
    4040
  • trunk/Source/WebCore/css/CSSFontVariationValue.cpp

    r253975 r254514  
    3030#include "CSSFontVariationValue.h"
    3131
    32 #include <wtf/text/StringBuilder.h>
    33 
    3432namespace WebCore {
    3533
     
    4341String CSSFontVariationValue::customCSSText() const
    4442{
    45     StringBuilder builder;
    46     builder.append('"');
    47     for (char c : m_tag)
    48         builder.append(c);
    49     builder.appendLiteral("\" ");
    50     builder.append(FormattedNumber::fixedPrecision(m_value));
    51     return builder.toString();
     43    return makeString('"', m_tag[0], m_tag[1], m_tag[2], m_tag[3], "\" ", m_value);
    5244}
    5345
  • trunk/Source/WebCore/css/CSSGradientValue.cpp

    r254164 r254514  
    701701            builder.append(", to(", stop.m_color->cssText(), ')');
    702702        else
    703             builder.append(", color-stop(", FormattedNumber::fixedPrecision(position), ", ", stop.m_color->cssText(), ')');
     703            builder.append(", color-stop(", position, ", ", stop.m_color->cssText(), ')');
    704704    }
    705705}
  • trunk/Source/WebCore/css/CSSKeyframeRule.cpp

    r253975 r254514  
    6060{
    6161    StringBuilder keyText;
    62 
    6362    for (size_t i = 0; i < m_keys.size(); ++i) {
    6463        if (i)
    6564            keyText.append(',');
    66         keyText.append(FormattedNumber::fixedPrecision(m_keys.at(i) * 100));
    67         keyText.append('%');
     65        keyText.append(m_keys[i] * 100, '%');
    6866    }
    69 
    7067    return keyText.toString();
    7168}
  • trunk/Source/WebCore/css/CSSTimingFunctionValue.cpp

    r253975 r254514  
    3333String CSSCubicBezierTimingFunctionValue::customCSSText() const
    3434{
    35     StringBuilder builder;
    36     builder.appendLiteral("cubic-bezier(");
    37     builder.append(FormattedNumber::fixedPrecision(m_x1));
    38     builder.appendLiteral(", ");
    39     builder.append(FormattedNumber::fixedPrecision(m_y1));
    40     builder.appendLiteral(", ");
    41     builder.append(FormattedNumber::fixedPrecision(m_x2));
    42     builder.appendLiteral(", ");
    43     builder.append(FormattedNumber::fixedPrecision(m_y2));
    44     builder.append(')');   
    45     return builder.toString();
     35    return makeString("cubic-bezier(", m_x1, ", ", m_y1, ", ", m_x2, ", ", m_y2, ')');
    4636}
    4737
  • trunk/Source/WebCore/css/MediaQueryEvaluator.cpp

    r253616 r254514  
    241241
    242242    auto& aspectRatio = downcast<CSSAspectRatioValue>(*value);
    243     return makeString(FormattedNumber::fixedWidth(aspectRatio.numeratorValue(), 6), '/', FormattedNumber::fixedWidth(aspectRatio.denominatorValue(), 6));
     243    return makeString(aspectRatio.numeratorValue(), '/', aspectRatio.denominatorValue());
    244244}
    245245
  • trunk/Source/WebCore/css/TransformFunctions.h

    r209805 r254514  
    3737class CSSToLengthConversionData;
    3838class CSSValue;
    39 class RenderStyle;
    40 
    41 struct Length;
    4239
    4340bool transformsForValue(const CSSValue&, const CSSToLengthConversionData&, TransformOperations&);
  • trunk/Source/WebCore/css/parser/CSSParserToken.cpp

    r254046 r254514  
    422422        if (m_numericSign == PlusSign)
    423423            builder.append('+');
    424         builder.append(FormattedNumber::fixedPrecision(numericValue()));
     424        builder.append(numericValue());
    425425        break;
    426426    case PercentageToken:
    427         builder.append(FormattedNumber::fixedPrecision(numericValue()));
    428         builder.append('%');
     427        builder.append(numericValue(), '%');
    429428        break;
    430429    case DimensionToken:
    431430        // This will incorrectly serialize e.g. 4e3e2 as 4000e2
    432         builder.append(FormattedNumber::fixedPrecision(numericValue()));
     431        builder.append(numericValue());
    433432        serializeIdentifier(value().toString(), builder);
    434433        break;
  • trunk/Source/WebCore/html/HTMLImageElement.cpp

    r254229 r254514  
    585585                result.appendLiteral(", ");
    586586            result.append(URL(base, candidate.string.toString()).string());
    587             if (candidate.density != UninitializedDescriptor) {
    588                 result.append(' ');
    589                 result.append(FormattedNumber::fixedPrecision(candidate.density));
    590                 result.append('x');
    591             }
    592             if (candidate.resourceWidth != UninitializedDescriptor) {
    593                 result.append(' ');
    594                 result.appendNumber(candidate.resourceWidth);
    595                 result.append('w');
    596             }
     587            if (candidate.density != UninitializedDescriptor)
     588                result.append(' ', candidate.density, 'x');
     589            if (candidate.resourceWidth != UninitializedDescriptor)
     590                result.append(' ', candidate.resourceWidth, 'w');
    597591        }
    598592        return result.toString();
  • trunk/Source/WebCore/html/track/VTTCue.cpp

    r252392 r254514  
    170170    if (cue->vertical() == horizontalKeyword())
    171171        setInlineStyleProperty(CSSPropertyLeft, position.first, CSSUnitType::CSS_PERCENTAGE);
    172     else if (cue->vertical() == verticalGrowingRightKeyword())
    173         setInlineStyleProperty(CSSPropertyLeft, makeString("calc(-", FormattedNumber::fixedWidth(videoSize.width(), 2), "px - ", FormattedNumber::fixedWidth(cue->getCSSSize(), 2), "px)"));
     172    else if (cue->vertical() == verticalGrowingRightKeyword()) {
     173        // FIXME: Why use calc to do the math instead of doing the subtraction here?
     174        setInlineStyleProperty(CSSPropertyLeft, makeString("calc(-", videoSize.width(), "px - ", cue->getCSSSize(), "px)"));
     175    }
    174176
    175177    double authorFontSize = std::min(videoSize.width(), videoSize.height()) * DEFAULTCAPTIONFONTSIZEPERCENTAGE / 100.0;
     
    221223        // maintaining the relative positions of the boxes in boxes to each
    222224        // other.
    223         setInlineStyleProperty(CSSPropertyTransform,
    224             makeString("translate(", FormattedNumber::fixedWidth(-position.first, 2), "%, ", FormattedNumber::fixedWidth(-position.second, 2), "%)"));
     225        setInlineStyleProperty(CSSPropertyTransform, makeString("translate(", -position.first, "%, ", -position.second, "%)"));
    225226
    226227        setInlineStyleProperty(CSSPropertyWhiteSpace, CSSValuePre);
  • trunk/Source/WebCore/inspector/InspectorOverlay.cpp

    r253916 r254514  
    792792                GraphicsContextStateSaver verticalLabelStateSaver(context);
    793793                context.translate(zoom(x) + 0.5f, scrollY);
    794                 context.drawText(font, TextRun(String::numberToStringFixedPrecision(x)), { 2, drawTopEdge ? rulerLabelSize : rulerLabelSize - rulerSize + font.fontMetrics().height() - 1.0f });
     794                context.drawText(font, TextRun(String::number(x)), { 2, drawTopEdge ? rulerLabelSize : rulerLabelSize - rulerSize + font.fontMetrics().height() - 1.0f });
    795795            }
    796796        }
     
    830830                context.translate(scrollX, zoom(y) + 0.5f);
    831831                context.rotate(drawLeftEdge ? -piOverTwoFloat : piOverTwoFloat);
    832                 context.drawText(font, TextRun(String::numberToStringFixedPrecision(y)), { 2, drawLeftEdge ? rulerLabelSize : rulerLabelSize - rulerSize });
     832                context.drawText(font, TextRun(String::number(y)), { 2, drawLeftEdge ? rulerLabelSize : rulerLabelSize - rulerSize });
    833833            }
    834834        }
     
    845845
    846846        auto viewportRect = pageView->visualViewportRect();
    847         auto viewportWidthText = String::numberToStringFixedPrecision(viewportRect.width() / pageZoomFactor);
    848         auto viewportHeightText = String::numberToStringFixedPrecision(viewportRect.height() / pageZoomFactor);
    849         TextRun viewportTextRun(makeString(viewportWidthText, "px", ' ', multiplicationSign, ' ', viewportHeightText, "px"));
     847        TextRun viewportTextRun(makeString(viewportRect.width() / pageZoomFactor, "px", ' ', multiplicationSign, ' ', viewportRect.height() / pageZoomFactor, "px"));
    850848
    851849        const float margin = 4;
  • trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp

    r253574 r254514  
    352352
    353353    StringBuilder builder;
    354     appendCSS(builder, CSSPropertyBorderRadius, makeString(FormattedNumber::fixedWidth(radius, 2), "px"), behavior == kMACaptionAppearanceBehaviorUseValue);
     354    appendCSS(builder, CSSPropertyBorderRadius, makeString(radius, "px"), behavior == kMACaptionAppearanceBehaviorUseValue);
    355355    return builder.toString();
    356356}
  • trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp

    r253975 r254514  
    7979    StringBuilder builder;
    8080    builder.appendLiteral("[ ");
    81     for (auto& offset : snapOffsets) {
    82         builder.append(FormattedNumber::fixedWidth(offset.toFloat(), 1));
    83         builder.append(' ');
    84     }
     81    for (auto& offset : snapOffsets)
     82        builder.append(offset.toFloat(), ' ');
    8583    builder.append(']');
    8684    return builder.toString();
     
    9189    StringBuilder builder;
    9290    builder.appendLiteral("[ ");
    93     for (auto& range : ranges) {
    94         builder.append('(');
    95         builder.append(FormattedNumber::fixedWidth(range.start.toFloat(), 1));
    96         builder.appendLiteral(", ");
    97         builder.append(FormattedNumber::fixedWidth(range.end.toFloat(), 1));
    98         builder.appendLiteral(") ");
    99     }
     91    for (auto& range : ranges)
     92        builder.append('(', range.start.toFloat(), ", ", range.end.toFloat(), ") ");
    10093    builder.append(']');
    10194    return builder.toString();
     
    10497static String snapPortOrAreaToString(const LayoutRect& rect)
    10598{
    106     return makeString("{{",
    107         FormattedNumber::fixedWidth(rect.x(), 1), ", ",
    108         FormattedNumber::fixedWidth(rect.y(), 1), "} {",
    109         FormattedNumber::fixedWidth(rect.width(), 1), ", ",
    110         FormattedNumber::fixedWidth(rect.height(), 1), "}}");
     99    return makeString("{{", rect.x().toFloat(), ", ", rect.y().toFloat(), "} {", rect.width().toFloat(), ", ", rect.height().toFloat(), "}}");
    111100}
    112101
  • trunk/Source/WebCore/platform/graphics/Color.cpp

    r254046 r254514  
    321321}
    322322
     323static char decimalDigit(unsigned number)
     324{
     325    ASSERT(number < 10);
     326    return '0' + number;
     327}
     328
     329static std::array<char, 4> serializedFractionDigitsForFractionalAlphaValue(uint8_t alpha)
     330{
     331    ASSERT(alpha > 0);
     332    ASSERT(alpha < 0xFF);
     333    if (((alpha * 100 + 0x7F) / 0xFF * 0xFF + 50) / 100 != alpha)
     334        return { { decimalDigit(alpha * 10 / 0xFF % 10), decimalDigit(alpha * 100 / 0xFF % 10), decimalDigit((alpha * 1000 + 0x7F) / 0xFF % 10), '\0' } };
     335    if (int thirdDigit = (alpha * 100 + 0x7F) / 0xFF % 10)
     336        return { { decimalDigit(alpha * 10 / 0xFF), decimalDigit(thirdDigit), '\0', '\0' } };
     337    return { { decimalDigit((alpha * 10 + 0x7F) / 0xFF), '\0', '\0', '\0' } };
     338}
     339
    323340String Color::cssText() const
    324341{
    325342    if (isExtended())
    326343        return asExtended().cssText();
    327 
    328     StringBuilder builder;
    329     builder.reserveCapacity(28);
    330     bool colorHasAlpha = !isOpaque();
    331     if (colorHasAlpha)
    332         builder.appendLiteral("rgba(");
    333     else
    334         builder.appendLiteral("rgb(");
    335 
    336     builder.appendNumber(static_cast<unsigned char>(red()));
    337     builder.appendLiteral(", ");
    338 
    339     builder.appendNumber(static_cast<unsigned char>(green()));
    340     builder.appendLiteral(", ");
    341 
    342     builder.appendNumber(static_cast<unsigned char>(blue()));
    343     if (colorHasAlpha) {
    344         // https://drafts.csswg.org/cssom/#serializing-css-values
    345         builder.appendLiteral(", ");
    346         int alpha = this->alpha();
    347         float rounded = round(alpha * 100 / 255.0f) / 100;
    348         if (round(rounded * 255) != alpha)
    349             rounded = round(alpha * 1000 / 255.0f) / 1000;
    350         builder.append(FormattedNumber::fixedPrecision(rounded));
    351     }
    352        
    353     builder.append(')');
    354     return builder.toString();
     344    uint8_t alpha = this->alpha();
     345    switch (alpha) {
     346    case 0:
     347        return makeString("rgba(", red(), ", ", green(), ", ", blue(), ", 0)");
     348    case 0xFF:
     349        return makeString("rgb(", red(), ", ", green(), ", ", blue(), ')');
     350    default:
     351        return makeString("rgba(", red(), ", ", green(), ", ", blue(), ", 0.", serializedFractionDigitsForFractionalAlphaValue(alpha).data(), ')');
     352    }
    355353}
    356354
  • trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp

    r253975 r254514  
    2727#include "ExtendedColor.h"
    2828
    29 #include "ColorSpace.h"
    3029#include <wtf/MathExtras.h>
    31 #include <wtf/dtoa.h>
    32 #include <wtf/text/StringBuilder.h>
    3330
    3431namespace WebCore {
     
    4138String ExtendedColor::cssText() const
    4239{
    43     StringBuilder builder;
    44     builder.reserveCapacity(40);
    45     builder.appendLiteral("color(");
    46 
     40    const char* colorSpace;
    4741    switch (m_colorSpace) {
    4842    case ColorSpace::SRGB:
    49         builder.appendLiteral("srgb ");
     43        colorSpace = "srgb";
    5044        break;
    5145    case ColorSpace::DisplayP3:
    52         builder.appendLiteral("display-p3 ");
     46        colorSpace = "display-p3";
    5347        break;
    5448    default:
     
    5751    }
    5852
    59     builder.append(FormattedNumber::fixedPrecision(red()));
    60     builder.append(' ');
    61 
    62     builder.append(FormattedNumber::fixedPrecision(green()));
    63     builder.append(' ');
    64 
    65     builder.append(FormattedNumber::fixedPrecision(blue()));
    66     if (!WTF::areEssentiallyEqual(alpha(), 1.0f)) {
    67         builder.appendLiteral(" / ");
    68         builder.append(FormattedNumber::fixedPrecision(alpha()));
    69     }
    70     builder.append(')');
    71 
    72     return builder.toString();
     53    if (WTF::areEssentiallyEqual(alpha(), 1.0f))
     54        return makeString("color(", colorSpace, ' ', red(), ' ', green(), ' ', blue(), ')');
     55    return makeString("color(", colorSpace, ' ', red(), ' ', green(), ' ', blue(), " / ", alpha(), ')');
    7356}
    7457
  • trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp

    r254087 r254514  
    13921392   
    13931393    StringBuilder logString;
    1394     logString.append(pad(' ', 12 + depth * 2, hex(reinterpret_cast<uintptr_t>(&layer), Lowercase)), " id ", backing->graphicsLayer()->primaryLayerID(), " (", FormattedNumber::fixedWidth(absoluteBounds.x().toFloat(), 3), ',', FormattedNumber::fixedWidth(absoluteBounds.y().toFloat(), 3), '-', FormattedNumber::fixedWidth(absoluteBounds.maxX().toFloat(), 3), ',', FormattedNumber::fixedWidth(absoluteBounds.maxY().toFloat(), 3), ") ", FormattedNumber::fixedWidth(backing->backingStoreMemoryEstimate() / 1024, 2), "KB");
     1394    logString.append(pad(' ', 12 + depth * 2, hex(reinterpret_cast<uintptr_t>(&layer), Lowercase)), " id ", backing->graphicsLayer()->primaryLayerID(), " (", absoluteBounds.x().toFloat(), ',', absoluteBounds.y().toFloat(), '-', absoluteBounds.maxX().toFloat(), ',', absoluteBounds.maxY().toFloat(), ") ", FormattedNumber::fixedWidth(backing->backingStoreMemoryEstimate() / 1024, 2), "KB");
    13951395
    13961396    if (!layer.renderer().style().hasAutoUsedZIndex())
  • trunk/Source/WebCore/svg/SVGAngleValue.cpp

    r242713 r254514  
    6767    switch (m_unitType) {
    6868    case SVG_ANGLETYPE_DEG:
    69         return makeString(FormattedNumber::fixedPrecision(m_valueInSpecifiedUnits), "deg");
    70     case SVG_ANGLETYPE_RAD:
    71         return makeString(FormattedNumber::fixedPrecision(m_valueInSpecifiedUnits), "rad");
    72     case SVG_ANGLETYPE_GRAD:
    73         return makeString(FormattedNumber::fixedPrecision(m_valueInSpecifiedUnits), "grad");
    74     case SVG_ANGLETYPE_UNSPECIFIED:
    75     case SVG_ANGLETYPE_UNKNOWN:
    76         return String::numberToStringFixedPrecision(m_valueInSpecifiedUnits);
     69        return makeString(m_valueInSpecifiedUnits, "deg");
     70    case SVG_ANGLETYPE_RAD:
     71        return makeString(m_valueInSpecifiedUnits, "rad");
     72    case SVG_ANGLETYPE_GRAD:
     73        return makeString(m_valueInSpecifiedUnits, "grad");
     74    case SVG_ANGLETYPE_UNSPECIFIED:
     75    case SVG_ANGLETYPE_UNKNOWN:
     76        return String::number(m_valueInSpecifiedUnits);
    7777    }
    7878
  • trunk/Source/WebCore/svg/SVGLengthList.h

    r249822 r254514  
    2828#include "SVGLength.h"
    2929#include "SVGValuePropertyList.h"
     30#include <wtf/text/StringBuilder.h>
    3031
    3132namespace WebCore {
  • trunk/Source/WebCore/svg/SVGLengthValue.cpp

    r253079 r254514  
    258258String SVGLengthValue::valueAsString() const
    259259{
    260     return makeString(FormattedNumber::fixedPrecision(m_valueInSpecifiedUnits), lengthTypeToString(m_lengthType));
     260    return makeString(m_valueInSpecifiedUnits, lengthTypeToString(m_lengthType));
    261261}
    262262
  • trunk/Source/WebCore/svg/SVGNumberList.h

    r253975 r254514  
    7979                builder.append(' ');
    8080
    81             builder.append(FormattedNumber::fixedPrecision(number->value()));
     81            builder.append(number->value());
    8282        }
    8383
  • trunk/Source/WebCore/svg/SVGPathStringBuilder.cpp

    r253975 r254514  
    5252static void appendFlag(StringBuilder& stringBuilder, bool flag)
    5353{
    54     stringBuilder.append(flag ? '1' : '0');
    55     stringBuilder.append(' ');
     54    stringBuilder.append(flag ? '1' : '0', ' ');
    5655}
    5756
    5857static void appendNumber(StringBuilder& stringBuilder, float number)
    5958{
    60     stringBuilder.append(FormattedNumber::fixedPrecision(number));
    61     stringBuilder.append(' ');
     59    // FIXME: Shortest form would be better, but fixed precision is required for now to smooth over precision errors caused by converting float to double and back in CGPath on Cocoa platforms.
     60    stringBuilder.append(FormattedNumber::fixedPrecision(number), ' ');
    6261}
    6362
    6463static void appendPoint(StringBuilder& stringBuilder, const FloatPoint& point)
    6564{
    66     stringBuilder.append(FormattedNumber::fixedPrecision(point.x()));
    67     stringBuilder.append(' ');
    68     stringBuilder.append(FormattedNumber::fixedPrecision(point.y()));
    69     stringBuilder.append(' ');
     65    appendNumber(stringBuilder, point.x());
     66    appendNumber(stringBuilder, point.y());
    7067}
    7168
  • trunk/Source/WebCore/svg/SVGPointList.h

    r253975 r254514  
    9494                builder.append(' ');
    9595
    96             builder.append(FormattedNumber::fixedPrecision(point->x()));
    97             builder.append(' ');
    98             builder.append(FormattedNumber::fixedPrecision(point->y()));
     96            builder.append(point->x(), ' ', point->y());
    9997        }
    10098
  • trunk/Source/WebCore/svg/SVGTransformValue.h

    r253975 r254514  
    22 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
    33 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
    4  * Copyright (C) 2019 Apple Inc.  All rights reserved.
     4 * Copyright (C) 2019 Apple Inc. All rights reserved.
    55 *
    66 * This library is free software; you can redistribute it and/or
     
    207207    }
    208208
    209     static String prefixForTransfromType(SVGTransformType type)
     209    static const char* prefixForTransfromType(SVGTransformType type)
    210210    {
    211211        switch (type) {
    212212        case SVG_TRANSFORM_UNKNOWN:
    213             return emptyString();
     213            return "";
    214214        case SVG_TRANSFORM_MATRIX:
    215             return "matrix("_s;
     215            return "matrix(";
    216216        case SVG_TRANSFORM_TRANSLATE:
    217             return "translate("_s;
     217            return "translate(";
    218218        case SVG_TRANSFORM_SCALE:
    219             return "scale("_s;
     219            return "scale(";
    220220        case SVG_TRANSFORM_ROTATE:
    221             return "rotate("_s;
     221            return "rotate(";
    222222        case SVG_TRANSFORM_SKEWX:
    223             return "skewX("_s;
     223            return "skewX(";
    224224        case SVG_TRANSFORM_SKEWY:
    225             return "skewY("_s;
     225            return "skewY(";
    226226        }
    227227        ASSERT_NOT_REACHED();
    228         return emptyString();
     228        return "";
    229229    }
    230230
     
    240240        if (builder.length() && builder[builder.length() - 1] != '(')
    241241            builder.append(' ');
     242        // FIXME: Shortest form would be better, but fixed precision is required for now to smooth over precision errors caused by converting float to double and back since we use AffineTransform to store transforms.
    242243        builder.append(FormattedNumber::fixedPrecision(number));
    243244        appendFixedPrecisionNumbers(builder, numbers...);
  • trunk/Source/WebCore/svg/properties/SVGPropertyTraits.h

    r253975 r254514  
    2828#include "QualifiedName.h"
    2929#include "SVGParserUtilities.h"
    30 #include <wtf/text/StringBuilder.h>
    31 #include <wtf/text/WTFString.h>
    3230
    3331namespace WebCore {
     
    104102        return number;
    105103    }
    106     static String toString(float type) { return String::numberToStringFixedPrecision(type); }
     104    static String toString(float type) { return String::number(type); }
    107105};
    108106
     
    140138    static String toString(const FloatPoint& type)
    141139    {
    142         StringBuilder builder;
    143         builder.append(FormattedNumber::fixedPrecision(type.x()));
    144         builder.append(' ');
    145         builder.append(FormattedNumber::fixedPrecision(type.y()));
    146         return builder.toString();
     140        return makeString(type.x(), ' ', type.y());
    147141    }
    148142};
     
    167161    static String toString(const FloatRect& type)
    168162    {
    169         StringBuilder builder;
    170         builder.append(FormattedNumber::fixedPrecision(type.x()));
    171         builder.append(' ');
    172         builder.append(FormattedNumber::fixedPrecision(type.y()));
    173         builder.append(' ');
    174         builder.append(FormattedNumber::fixedPrecision(type.width()));
    175         builder.append(' ');
    176         builder.append(FormattedNumber::fixedPrecision(type.height()));
    177         return builder.toString();
     163        return makeString(type.x(), ' ', type.y(), ' ', type.width(), ' ', type.height());
    178164    }
    179165};
  • trunk/Source/WebCore/testing/Internals.cpp

    r254373 r254514  
    16921692    auto rects = contextDocument()->markers().renderedRectsForMarkers(markerType);
    16931693
     1694    // FIXME: Using fixed precision here for width because of test results that contain numbers with specific precision. Would be nice to update the test results and move to default formatting.
    16941695    StringBuilder rectString;
    16951696    rectString.appendLiteral("marker rects: ");
    1696     for (const auto& rect : rects) {
    1697         rectString.append('(');
    1698         rectString.append(FormattedNumber::fixedPrecision(rect.x()));
    1699         rectString.appendLiteral(", ");
    1700         rectString.append(FormattedNumber::fixedPrecision(rect.y()));
    1701         rectString.appendLiteral(", ");
    1702         rectString.append(FormattedNumber::fixedPrecision(rect.width()));
    1703         rectString.appendLiteral(", ");
    1704         rectString.append(FormattedNumber::fixedPrecision(rect.height()));
    1705         rectString.appendLiteral(") ");
    1706     }
     1697    for (const auto& rect : rects)
     1698        rectString.append('(', rect.x(), ", ", rect.y(), ", ", FormattedNumber::fixedPrecision(rect.width()), ", ", rect.height(), ") ");
    17071699    return rectString.toString();
    17081700}
     
    18851877    restrictScaleFactorToInitialScaleIfNotUserScalable(attributes);
    18861878
     1879    // FIXME: Using fixed precision here because of test results that contain numbers with specific precision. Would be nice to update the test results and move to default formatting.
    18871880    return makeString("viewport size ", FormattedNumber::fixedPrecision(attributes.layoutSize.width()), 'x', FormattedNumber::fixedPrecision(attributes.layoutSize.height()), " scale ", FormattedNumber::fixedPrecision(attributes.initialScale), " with limits [", FormattedNumber::fixedPrecision(attributes.minimumScale), ", ", FormattedNumber::fixedPrecision(attributes.maximumScale), "] and userScalable ", (attributes.userScalable ? "true" : "false"));
    18881881}
     
    34473440
    34483441    StringBuilder result;
    3449     result.appendLiteral("type=");
    3450     result.append(cursorTypeToString(cursor.type()));
    3451     result.appendLiteral(" hotSpot=");
    3452     result.appendNumber(cursor.hotSpot().x());
    3453     result.append(',');
    3454     result.appendNumber(cursor.hotSpot().y());
     3442    result.append("type=", cursorTypeToString(cursor.type()), " hotSpot=", cursor.hotSpot().x(), ',', cursor.hotSpot().y());
    34553443    if (cursor.image()) {
    34563444        FloatSize size = cursor.image()->size();
    3457         result.appendLiteral(" image=");
    3458         result.append(FormattedNumber::fixedPrecision(size.width()));
    3459         result.append('x');
    3460         result.append(FormattedNumber::fixedPrecision(size.height()));
     3445        result.append(" image=", size.width(), 'x', size.height());
    34613446    }
    34623447#if ENABLE(MOUSE_CURSOR_SCALE)
    3463     if (cursor.imageScaleFactor() != 1) {
    3464         result.appendLiteral(" scale=");
    3465         result.append(FormattedNumber::fixedPrecision(cursor.imageScaleFactor(), 8));
    3466     }
     3448    if (cursor.imageScaleFactor() != 1)
     3449        result.append(" scale=", cursor.imageScaleFactor());
    34673450#endif
    34683451    return result.toString();
  • trunk/Source/WebCore/xml/XPathValue.cpp

    r242713 r254514  
    127127            if (std::isinf(m_number))
    128128                return std::signbit(m_number) ? "-Infinity"_s : "Infinity"_s;
    129             return String::numberToStringFixedPrecision(m_number);
     129            return String::number(m_number);
    130130        case BooleanValue:
    131131            return m_bool ? "true"_s : "false"_s;
  • trunk/Source/WebKit/ChangeLog

    r254511 r254514  
     12020-01-13  Darin Adler  <darin@apple.com>
     2
     3        Use even more "shortest form" formatting, and less "fixed precision" and "fixed width"
     4        https://bugs.webkit.org/show_bug.cgi?id=198918
     5
     6        Reviewed by Sam Weinig.
     7
     8        * NetworkProcess/cache/NetworkCache.cpp:
     9        (WebKit::NetworkCache::Cache::dumpContentsToFile): Use shortest instead of fixed.
     10        Also use makeString instead of StringBuilder.
     11
     12        * NetworkProcess/cache/NetworkCacheEntry.cpp:
     13        (WebKit::NetworkCache::Entry::asJSON const): Use shortest instead of fixed.
     14        Also use multiple-argument append on StringBuilder to make the function shorter
     15        and easier to read.
     16        * Shared/Gamepad/GamepadData.cpp:
     17        (WebKit::GamepadData::loggingString const): Ditto.
     18
     19        * UIProcess/ViewGestureController.cpp:
     20        (WebKit::ViewGestureController::SnapshotRemovalTracker::startWatchdog):
     21        Use shortest instead of fixed.
     22
    1232020-01-14  Víctor Manuel Jáquez Leal  <vjaquez@igalia.com>
    224
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp

    r254055 r254514  
    576576    m_storage->traverse(resourceType(), flags, [fd, totals, capacity](const Storage::Record* record, const Storage::RecordInfo& info) mutable {
    577577        if (!record) {
    578             StringBuilder epilogue;
    579             epilogue.appendLiteral("{}\n],\n");
    580             epilogue.appendLiteral("\"totals\": {\n");
    581             epilogue.appendLiteral("\"capacity\": ");
    582             epilogue.appendNumber(capacity);
    583             epilogue.appendLiteral(",\n");
    584             epilogue.appendLiteral("\"count\": ");
    585             epilogue.appendNumber(totals.count);
    586             epilogue.appendLiteral(",\n");
    587             epilogue.appendLiteral("\"bodySize\": ");
    588             epilogue.appendNumber(totals.bodySize);
    589             epilogue.appendLiteral(",\n");
    590             epilogue.appendLiteral("\"averageWorth\": ");
    591             epilogue.append(FormattedNumber::fixedPrecision(totals.count ? totals.worth / totals.count : 0));
    592             epilogue.appendLiteral("\n");
    593             epilogue.appendLiteral("}\n}\n");
    594             auto writeData = epilogue.toString().utf8();
     578            CString writeData = makeString(
     579                "{}\n"
     580                "],\n"
     581                "\"totals\": {\n"
     582                "\"capacity\": ", capacity, ",\n"
     583                "\"count\": ", totals.count, ",\n"
     584                "\"bodySize\": ", totals.bodySize, ",\n"
     585                "\"averageWorth\": ", totals.count ? totals.worth / totals.count : 0, "\n"
     586                "}\n}\n"
     587            ).utf8();
    595588            writeToFile(fd, writeData.data(), writeData.length());
    596589            closeFile(fd);
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheEntry.cpp

    r253975 r254514  
    212212void Entry::asJSON(StringBuilder& json, const Storage::RecordInfo& info) const
    213213{
    214     json.appendLiteral("{\n");
    215     json.appendLiteral("\"hash\": ");
     214    json.appendLiteral("{\n"
     215        "\"hash\": ");
    216216    json.appendQuotedJSONString(m_key.hashAsString());
    217     json.appendLiteral(",\n");
    218     json.appendLiteral("\"bodySize\": ");
    219     json.appendNumber(info.bodySize);
    220     json.appendLiteral(",\n");
    221     json.appendLiteral("\"worth\": ");
    222     json.append(FormattedNumber::fixedPrecision(info.worth));
    223     json.appendLiteral(",\n");
    224     json.appendLiteral("\"partition\": ");
     217    json.append(",\n"
     218        "\"bodySize\": ", info.bodySize, ",\n"
     219        "\"worth\": ", info.worth, ",\n"
     220        "\"partition\": ");
    225221    json.appendQuotedJSONString(m_key.partition());
    226     json.appendLiteral(",\n");
    227     json.appendLiteral("\"timestamp\": ");
    228     json.append(FormattedNumber::fixedPrecision(m_timeStamp.secondsSinceEpoch().milliseconds()));
    229     json.appendLiteral(",\n");
    230     json.appendLiteral("\"URL\": ");
     222    json.append(",\n"
     223        "\"timestamp\": ", m_timeStamp.secondsSinceEpoch().milliseconds(), ",\n"
     224        "\"URL\": ");
    231225    json.appendQuotedJSONString(m_response.url().string());
    232     json.appendLiteral(",\n");
    233     json.appendLiteral("\"bodyHash\": ");
     226    json.appendLiteral(",\n"
     227        "\"bodyHash\": ");
    234228    json.appendQuotedJSONString(info.bodyHash);
    235     json.appendLiteral(",\n");
    236     json.appendLiteral("\"bodyShareCount\": ");
    237     json.appendNumber(info.bodyShareCount);
    238     json.appendLiteral(",\n");
    239     json.appendLiteral("\"headers\": {\n");
     229    json.append(",\n"
     230        "\"bodyShareCount\": ", info.bodyShareCount, ",\n"
     231        "\"headers\": {\n");
    240232    bool firstHeader = true;
    241233    for (auto& header : m_response.httpHeaderFields()) {
     
    248240        json.appendQuotedJSONString(header.value);
    249241    }
    250     json.appendLiteral("\n}\n");
    251     json.appendLiteral("}");
    252 }
    253 
    254 }
    255 }
     242    json.appendLiteral("\n"
     243        "}\n"
     244        "}");
     245}
     246
     247}
     248}
  • trunk/Source/WebKit/Shared/Gamepad/GamepadData.cpp

    r253975 r254514  
    8888
    8989#if !LOG_DISABLED
     90
    9091String GamepadData::loggingString() const
    9192{
    9293    StringBuilder builder;
    9394
    94     builder.appendNumber(m_axisValues.size());
    95     builder.appendLiteral(" axes, ");
    96     builder.appendNumber(m_buttonValues.size());
    97     builder.appendLiteral(" buttons\n");
     95    builder.append(m_axisValues.size(), " axes, ", m_buttonValues.size(), " buttons\n");
    9896
    99     for (size_t i = 0; i < m_axisValues.size(); ++i) {
    100         builder.appendLiteral(" Axis ");
    101         builder.appendNumber(i);
    102         builder.appendLiteral(": ");
    103         builder.append(FormattedNumber::fixedPrecision(m_axisValues[i]));
    104     }
     97    for (size_t i = 0; i < m_axisValues.size(); ++i)
     98        builder.append(" Axis ", i, ": ", m_axisValues[i]);
    10599
    106100    builder.append('\n');
    107     for (size_t i = 0; i < m_buttonValues.size(); ++i) {
    108         builder.appendLiteral(" Button ");
    109         builder.appendNumber(i);
    110         builder.appendLiteral(": ");
    111         builder.append(FormattedNumber::fixedPrecision(m_buttonValues[i]));
    112     }
     101
     102    for (size_t i = 0; i < m_buttonValues.size(); ++i)
     103        builder.append(" Button ", i, ": ", FormattedNumber::fixedPrecision(m_buttonValues[i]));
    113104
    114105    return builder.toString();
    115106}
     107
    116108#endif
    117109
  • trunk/Source/WebKit/UIProcess/ViewGestureController.cpp

    r253514 r254514  
    388388void ViewGestureController::SnapshotRemovalTracker::startWatchdog(Seconds duration)
    389389{
    390     log(makeString("(re)started watchdog timer for ", FormattedNumber::fixedWidth(duration.seconds(), 1), " seconds"));
     390    log(makeString("(re)started watchdog timer for ", duration.seconds(), " seconds"));
    391391    m_watchdogTimer.startOneShot(duration);
    392392}
Note: See TracChangeset for help on using the changeset viewer.