Eliminate unnecessary String temporaries by using StringConcatenateNumbers
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Feb 2019 21:00:05 +0000 (21:00 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Feb 2019 21:00:05 +0000 (21:00 +0000)
commited669da4935b4ff32f585c0023e7b305bbccedc1
tree1aed79db6687480899b2b4e638b52a7b231e0926
parent81c12869db6c08753608fbc1615699dbb402ec1d
Eliminate unnecessary String temporaries by using StringConcatenateNumbers
https://bugs.webkit.org/show_bug.cgi?id=194021

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

* inspector/agents/InspectorConsoleAgent.cpp:
(Inspector::InspectorConsoleAgent::count): Remove String::number and let
makeString do the conversion without allocating/destroying a String.
* inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::objectGroupForBreakpointAction): Ditto.
(Inspector::InspectorDebuggerAgent::setBreakpointByUrl): Ditto.
(Inspector::InspectorDebuggerAgent::setBreakpoint): Ditto.
* runtime/JSGenericTypedArrayViewInlines.h:
(JSC::JSGenericTypedArrayView<Adaptor>::defineOwnProperty): Ditto.
* runtime/NumberPrototype.cpp:
(JSC::numberProtoFuncToFixed): Use String::numberToStringFixedWidth instead
of calling numberToFixedWidthString to do the same thing.
(JSC::numberProtoFuncToPrecision): Use String::number instead of calling
numberToFixedPrecisionString to do the same thing.
* runtime/SamplingProfiler.cpp:
(JSC::SamplingProfiler::reportTopFunctions): Ditto.

Source/WebCore:

For floating point numbers, String::number gives a fixed precision result,
stripping trailing zeroes. When possible, I changed the code to instead use the
equivalent of String::numberToStringECMAScript, which is what makeString does by
default for floating point, gives the same results for many cases, and gives
better results in many others. However, for floats, we do not yet have a good
implementation, so instead I used FormattedNumber::fixedPrecision to match
the old behavior.

* Modules/indexeddb/shared/IDBTransactionInfo.cpp:
(WebCore::IDBTransactionInfo::loggingString const): Remove String::number and let
makeString do the conversion without allocating/destroying a String.
* Modules/websockets/ThreadableWebSocketChannel.cpp:
(WebCore::ThreadableWebSocketChannel::create): Ditto.
* Modules/websockets/WebSocket.cpp:
(WebCore::WebSocket::connect): Ditto. Added a cast to "unsigned" to sidestep the
ambiguity with 16-bit unsigned types that are sometimes used for numbers (uint16_t)
and sometimes used for UTF-16 code units (UChar) and can be the same type.

* Modules/websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::didFailSocketStream): Use ASCIILiteral when intializing
a string instead of just a normal C literal. Switched to makeString so we could
remove String::number and do the conversion without allocating/destroying a String.
(WebCore::WebSocketChannel::didFail): Ditto.
(WebCore::WebSocketChannel::processFrame): Ditto.
* Modules/websockets/WebSocketFrame.cpp:
(WebCore::WebSocketFrame::parseFrame): Ditto.
* Modules/websockets/WebSocketHandshake.cpp:
(WebCore::WebSocketHandshake::readServerHandshake): Ditto.
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::positionalDescriptionForMSAA const): Ditto.
* bindings/js/JSDOMConvertNumbers.cpp:
(WebCore::rangeErrorString): Ditto.
* css/CSSAspectRatioValue.cpp:
(WebCore::CSSAspectRatioValue::customCSSText const): Ditto. Used
FormattedNumber::fixedPrecision since these are floats.

* css/DOMMatrixReadOnly.cpp:
(WebCore::DOMMatrixReadOnly::toString const): Use
StringBuilder::builder.appendECMAScriptNumber instead of
String::numberToStringECMAScript so we can do it without allocating/destroying
a String.
* css/WebKitCSSMatrix.cpp:
(WebCore::WebKitCSSMatrix::toString const): Ditto.

* dom/MessagePortIdentifier.h:
(WebCore::MessagePortIdentifier::logString const): Remove String::number and let
makeString do the conversion without allocating/destroying a String.

* editing/cocoa/DataDetection.mm:
(WebCore::dataDetectorStringForPath): Remove unnecessary type casts on values
passed to String::number and to StringBuilder::appendNumber. These could do
harm if the values were out of range, and should not be necessary.

* history/BackForwardItemIdentifier.h:
(WebCore::BackForwardItemIdentifier::logString const): Remove String::number
and let makeString do the conversion without allocating/destroying a String.
* html/FTPDirectoryDocument.cpp:
(WebCore::processFileDateString): Ditto.
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::getUniformLocation): Ditto.
(WebCore::WebGLRenderingContextBase::checkTextureCompleteness): Ditto.
* inspector/agents/WebConsoleAgent.cpp:
(WebCore::WebConsoleAgent::didReceiveResponse): Ditto.
* loader/WorkerThreadableLoader.cpp:
(WebCore::WorkerThreadableLoader::loadResourceSynchronously): Ditto.
* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::didFailLoadingManifest): Ditto.
* page/PageSerializer.cpp:
(WebCore::PageSerializer::urlForBlankFrame): Ditto.
* page/PrintContext.cpp:
(WebCore::PrintContext::pageProperty): Ditto.
(WebCore::PrintContext::pageSizeAndMarginsInPixels): Ditto.

* page/WheelEventTestTrigger.cpp:
(WebCore::dumpState): Use StringBuilder::appendNumber instead of
String::number so we can do it without allocating/destroying a String.
Also use StringBuilder::appendLiteral on a literal.

* page/cocoa/ResourceUsageOverlayCocoa.mm:
(WebCore::ResourceUsageOverlay::platformDraw): Pass explicit
KeepTrailingZeros to FormattedNumber::fixedPrecision to preserve behavior,
since default is now to truncate trailing zeros.

* platform/graphics/Color.cpp:
(WebCore::Color::cssText): Use StringBuilder::appendNumber instead of
calling numberToFixedPrecisionString to do the same thing.
* platform/graphics/ExtendedColor.cpp:
(WebCore::ExtendedColor::cssText): Ditto.

* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::animationIdentifier): Remove String::number and let makeString
do the conversion without allocating/destroying a String. Had to add
a typecast to convert the enumeration into an integer.
* platform/graphics/ca/cocoa/PlatformCAFiltersCocoa.mm:
(WebCore::PlatformCAFilters::setFiltersOnLayer): Ditto.
* platform/graphics/cocoa/FontPlatformDataCocoa.mm:
(WebCore::FontPlatformData::description const): Ditto.

* platform/mock/mediasource/MockSourceBufferPrivate.cpp:
(WebCore::MockMediaSample::MockMediaSample): Use AtomicString::number
instead of String::number to avoid unneccessarily allocating an additional
temporary String when an AtomicString already exists.

* platform/network/cf/SocketStreamHandleImplCFNet.cpp:
(WebCore::SocketStreamHandleImpl::reportErrorToClient): Remove String::number
and let makeString do the conversion without allocating/destroying a String.
* platform/sql/SQLiteDatabase.cpp:
(WebCore::SQLiteDatabase::setMaximumSize): Ditto.
(WebCore::SQLiteDatabase::setSynchronous): Ditto. Had to add a typecast to
convert the enumeration into an integer.
* svg/SVGAngleValue.cpp:
(WebCore::SVGAngleValue::valueAsString const): Ditto.
* svg/SVGLengthValue.cpp:
(WebCore::SVGLengthValue::valueAsString const): Ditto.
* testing/Internals.cpp:
(WebCore::Internals::configurationForViewport): Ditto. Used
FormattedNumber::fixedPrecision since these are floats.
(WebCore::Internals::getCurrentCursorInfo): Use StringBuilder::appendNumber
instead of calling numberToFixedPrecisionString to do the same thing.
(WebCore::Internals::queueMicroTask): Remove String::number and let makeString
do the conversion without allocating/destroying a String.
(WebCore::appendOffsets): Use StringBuilder::appendNumber instead of
String::number so we can do it without allocating/destroying a String.

* workers/service/ServiceWorkerClientIdentifier.h:
(WebCore::ServiceWorkerClientIdentifier::toString const): Remove String::number
and let makeString do the conversion without allocating/destroying a String.
* workers/service/server/RegistrationDatabase.cpp:
(WebCore::databaseFilenameFromVersion): Ditto.

Source/WebKit:

* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::escapeIDForJSON): Use an ASCIILiteral to create a String.

* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::makeVersionedDirectoryPath): Remove String::number and let
makeString do the conversion without allocating/destroying a String.

* NetworkProcess/mac/RemoteNetworkingContext.mm: Removed "using namespace WebCore".
(WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession): Remove String::number
and let makeString do the conversion without allocating/destroying a String.

* NetworkProcess/webrtc/NetworkMDNSRegister.cpp: Removed "using namespace WebCore".
(WebKit::registerMDNSNameCallback): Added explicit WebCore prefix as needed.
(WebKit::NetworkMDNSRegister::registerMDNSName): Ditto. Also remove String::number
and let makeString do the conversion without allocating/destroying a String.

* UIProcess/WebPageGroup.cpp:
(WebKit::pageGroupData): Remove String::number and let makeString do the conversion
without allocating/destroying a String.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::createInspectorTargets): Ditto.
* UIProcess/ios/WKLegacyPDFView.mm:
(-[WKLegacyPDFView _URLForLinkAnnotation:]): Ditto.
* WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp:
(WebKit::uniqueWorldName): Ditto.
* WebProcess/WebPage/WebPageInspectorTarget.cpp:
(WebKit::WebPageInspectorTarget::identifier const): Ditto.

Source/WTF:

* wtf/URL.cpp:
(WTF::URL::setPort): Remove String::number and let makeString do the conversion
without allocating/destroying a String. Added a cast to "unsigned" to sidestep the
ambiguity with 16-bit unsigned types that are sometimes used for numbers (uint16_t)
and sometimes used for UTF-16 code units (UChar) and can be the same type.

* wtf/text/StringConcatenateNumbers.h:
Changed FormattedNumber::fixedPrecision to more closely match String::number and
StringBuilder::appendNumber by defaulting to truncating trailing zeros and using
a named enumeration for the truncation policy rather than a boolean.

Tools:

* TestWebKitAPI/Tests/WTF/StringConcatenate.cpp:
(TestWebKitAPI::TEST): Change tests to use EXPECT_STREQ so failure messages are easier
to understand. Updated tests for changes to FormattedNumber::fixedPrecision.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241244 268f45cc-cd09-0410-ab3c-d52691b4dbfc
58 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/agents/InspectorConsoleAgent.cpp
Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp
Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h
Source/JavaScriptCore/runtime/NumberPrototype.cpp
Source/JavaScriptCore/runtime/SamplingProfiler.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/URL.cpp
Source/WTF/wtf/text/StringConcatenateNumbers.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.cpp
Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp
Source/WebCore/Modules/websockets/WebSocket.cpp
Source/WebCore/Modules/websockets/WebSocketChannel.cpp
Source/WebCore/Modules/websockets/WebSocketFrame.cpp
Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/bindings/js/JSDOMConvertNumbers.cpp
Source/WebCore/css/CSSAspectRatioValue.cpp
Source/WebCore/css/DOMMatrixReadOnly.cpp
Source/WebCore/css/WebKitCSSMatrix.cpp
Source/WebCore/dom/MessagePortIdentifier.h
Source/WebCore/editing/cocoa/DataDetection.mm
Source/WebCore/history/BackForwardItemIdentifier.h
Source/WebCore/html/FTPDirectoryDocument.cpp
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/inspector/agents/WebConsoleAgent.cpp
Source/WebCore/loader/WorkerThreadableLoader.cpp
Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp
Source/WebCore/page/PageSerializer.cpp
Source/WebCore/page/PrintContext.cpp
Source/WebCore/page/WheelEventTestTrigger.cpp
Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm
Source/WebCore/platform/graphics/Color.cpp
Source/WebCore/platform/graphics/ExtendedColor.cpp
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
Source/WebCore/platform/graphics/ca/cocoa/PlatformCAFiltersCocoa.mm
Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm
Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp
Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp
Source/WebCore/platform/sql/SQLiteDatabase.cpp
Source/WebCore/svg/SVGAngleValue.cpp
Source/WebCore/svg/SVGLengthValue.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h
Source/WebCore/workers/service/server/RegistrationDatabase.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp
Source/WebKit/NetworkProcess/mac/RemoteNetworkingContext.mm
Source/WebKit/NetworkProcess/webrtc/NetworkMDNSRegister.cpp
Source/WebKit/UIProcess/WebPageGroup.cpp
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/ios/WKLegacyPDFView.mm
Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp
Source/WebKit/WebProcess/WebPage/WebPageInspectorTarget.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/StringConcatenate.cpp