Convert additional String::format clients to alternative approaches
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Feb 2019 04:05:55 +0000 (04:05 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Feb 2019 04:05:55 +0000 (04:05 +0000)
commita940b3085024c59212e6c085faf535362b6ba583
tree9b5c9d49dc6131fdde28c19043754365cfec9854
parentd29294b1413ca01350d4a94eaafb160386e703a2
Convert additional String::format clients to alternative approaches
https://bugs.webkit.org/show_bug.cgi?id=192746

Reviewed by Alexey Proskuryakov.

Source/JavaScriptCore:

* inspector/agents/InspectorConsoleAgent.cpp:
(Inspector::InspectorConsoleAgent::stopTiming): Use makeString
and FormattedNumber::fixedWidth.

Source/WebCore:

This round of conversions covers less-trivial cases such as floating
point numerals and hexadecimal. Not yet taking on pointer serialization
("%p") or padding with spaces of zero digits, so call sites using those
have been left untouched.

In some cases these new idioms are a bit clumsy, and we could follow up
with additional convenience functions to make them more elegant.

* Modules/indexeddb/IDBKeyData.cpp:
(WebCore::IDBKeyData::loggingString const): Use more ASCIILiteral and
more appendLiteral for efficiency. Use upperNibbleToLowercaseASCIIHexDigit,
lowerNibbleToLowercaseASCIIHexDigit, and also makeString and FormattedNumber.

* css/MediaQueryEvaluator.cpp:
(WebCore::aspectRatioValueAsString): Use makeString and FormattedNumber.
Doing it this way makes it a little clearer that we have an unpleasant
use of fixed 6-digit precision here.

* html/FTPDirectoryDocument.cpp:
(WebCore::processFilesizeString): Use makeString and FormattedNumber.
* html/track/VTTCue.cpp:
(WebCore::VTTCueBox::applyCSSProperties): Ditto.
* page/CaptionUserPreferencesMediaAF.cpp:
(WebCore::CaptionUserPreferencesMediaAF::windowRoundedCornerRadiusCSS const): Ditto.
* page/History.cpp:
(WebCore::History::stateObjectAdded): Ditto.
* page/cocoa/ResourceUsageOverlayCocoa.mm:
(WebCore::formatByteNumber): Ditto.
(WebCore::gcTimerString): Use String::number.
(WebCore::ResourceUsageOverlay::platformDraw): Use makeString and FormattedNumber.

* page/scrolling/AxisScrollSnapOffsets.cpp:
(WebCore::snapOffsetsToString): Removed some unnecessary copying in the for loop,
use appendLiteral, and use appendFixedWidthNumber.
(WebCore::snapOffsetRangesToString): Ditto.
(WebCore::snapPortOrAreaToString): Use makeString and FormattedNumber.

* platform/animation/TimingFunction.cpp:
(WebCore::TimingFunction::cssText const): Use makeString.

* platform/cocoa/KeyEventCocoa.mm:
(WebCore::keyIdentifierForCharCode): Use makeString and the ASCIIHexDigit
functions.
* platform/graphics/Color.cpp:
(WebCore::Color::nameForRenderTreeAsText const): Ditto.

* platform/mock/MockRealtimeVideoSource.cpp:
(WebCore::MockRealtimeVideoSource::drawText): Use makeString and FormattedNumber.

* platform/text/PlatformLocale.cpp:
(WebCore::DateTimeStringBuilder::visitField): Use String::numberToStringFixedWidth.

Source/WebCore/PAL:

* pal/FileSizeFormatter.cpp:
(fileSizeDescription): Use makeString and FormattedNumber.

Source/WebKit:

* UIProcess/Cocoa/ViewGestureController.cpp:
(WebKit::ViewGestureController::SnapshotRemovalTracker::startWatchdog):
Use makeString and FormattedNumber.

* UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm:
(WebKit::LocalAuthenticator::getAssertion): Added a comment about an
incorrect format specifier and left this code as is for now.

Source/WTF:

* wtf/JSONValues.cpp:
(WTF::appendDoubleQuotedStringEscapedCharacter): Renamed from
escapeChar and reordered arguments to make sense as an append function.
(WTF::appendDoubleQuotedString): Renamed from doubleQuoteString,
reordered arguments to make sense as an append function, take a
StringView instead of a String, used early exit to make the code
a bit easier to read. Use the ASCIIHexDigit functions to construct
a hex number a nibble at a time rather than using String::format.
(WTF::JSONImpl::Value::writeJSON const): Update for name change.
(WTF::JSONImpl::ObjectBase::writeJSON const): Ditto.

Tools:

* WebKitTestRunner/TestController.cpp:
(WTR::originUserVisibleName): Use makeString and reduce the use of std::string
as an intermediate in code that ultimately constructs a WTF::String.
(WTR::userMediaOriginHash): Use makeString.
(WTR::TestController::didNavigateWithNavigationData): More of the same.
(WTR::TestController::didPerformClientRedirect): Ditto.
(WTR::TestController::didPerformServerRedirect): Ditto.
(WTR::TestController::didUpdateHistoryTitle): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240892 268f45cc-cd09-0410-ab3c-d52691b4dbfc
25 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/agents/InspectorConsoleAgent.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/JSONValues.cpp
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBKeyData.cpp
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/pal/FileSizeFormatter.cpp
Source/WebCore/css/MediaQueryEvaluator.cpp
Source/WebCore/html/FTPDirectoryDocument.cpp
Source/WebCore/html/track/VTTCue.cpp
Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp
Source/WebCore/page/History.cpp
Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm
Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp
Source/WebCore/platform/animation/TimingFunction.cpp
Source/WebCore/platform/cocoa/KeyEventCocoa.mm
Source/WebCore/platform/graphics/Color.cpp
Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp
Source/WebCore/platform/text/PlatformLocale.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/ViewGestureController.cpp
Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm
Tools/ChangeLog
Tools/WebKitTestRunner/TestController.cpp