haikuwebkit/Source/WTF/wtf/HexNumber.h

98 lines
3.3 KiB
C
Raw Permalink Normal View History

2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
/*
* Copyright (C) 2011 Research In Motion Limited. All rights reserved.
Continue reducing use of String::format, now focusing on hex: "%p", "%x", etc. https://bugs.webkit.org/show_bug.cgi?id=194752 Reviewed by Daniel Bates. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): Added back the "0x" that was removed when changing this file to use appendUnsignedAsHex instead of "%p". The intent at that time was to keep behavior the same, so let's do that. * parser/Lexer.cpp: (JSC::Lexer<T>::invalidCharacterMessage const): Use makeString and hex instead of String::format and "%04x". Source/WebCore: * Modules/websockets/WebSocket.cpp: Added an include of HexNumber.h. This previously got included because of Logger.h, but that no longer pulls in HexNumber.h. * css/CSSMarkup.cpp: Removed unneeded include of StringBuffer.h. * css/CSSPrimitiveValue.cpp: Ditto. * css/CSSUnicodeRangeValue.cpp: (WebCore::CSSUnicodeRangeValue::customCSSText const): Use makeString and hex instead of String::format and "%x". * html/HTMLMediaElement.h: (WTF::ValueToString<WebCore::TextTrackCue::string): Use a non-template function, TextTrackCure::debugString, so we don't need to use HextNumber.h in a header. * html/canvas/WebGLRenderingContextBase.cpp: (GetErrorString): Use makeString and hex instead of String::format and "%04x". * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::debugString const): Added. Moved string conversion here from HTMLMediaElement.h and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * html/track/TextTrackCue.h: Added TextTrackCue::debugString. * page/linux/ResourceUsageOverlayLinux.cpp: (WebCore::formatByteNumber): Use makeString and FormattedNumber::fixedWidth instead of String::format and "%.1f" etc. * platform/cocoa/KeyEventCocoa.mm: (WebCore::keyIdentifierForCharCode): Use the new hex function here instead of the old code that did each of the four characters explicitly. * platform/gamepad/mac/HIDGamepad.cpp: (WebCore::HIDGamepad::HIDGamepad): Use makeString instead of String::format. * platform/graphics/Color.cpp: (WebCore::Color::nameForRenderTreeAsText const): Use hex instead of doing each digit separately. * platform/graphics/FloatPolygon.cpp: (WebCore::FloatPolygonEdge::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * platform/graphics/FloatPolygon.h: Updated for the above. * platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::GraphicsLayerCA::setName): Use makeString instead of String::format. (WebCore::GraphicsLayerCA::recursiveCommitChanges): DItto. * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::load): Ditto. (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Ditto. * platform/gtk/PlatformKeyboardEventGtk.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForGdkKeyCode): Ditto. * platform/libwpe/PlatformKeyboardEventLibWPE.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForWPEKeyCode): Ditto. * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: (WebCore::GStreamerVideoEncoder::makeElement): Ditto. (WebCore::GStreamerVideoEncoder::InitEncode): Ditto. * platform/text/TextCodecLatin1.cpp: Removed unneeded include of StringBuffer.h and "using namespace WTF". * platform/win/GDIObjectCounter.cpp: (WebCore::GDIObjectCounter::GDIObjectCounter): Use makeString instead of String::format. * platform/win/KeyEventWin.cpp: (WebCore::keyIdentifierForWindowsKeyCode): Ditto. * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/FloatingObjects.h: Updated for the above. * rendering/RenderFragmentContainer.cpp: (WebCore::RenderFragmentContainer::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/RenderFragmentContainer.h: Updated for the above. * rendering/RenderFragmentedFlow.h: Ditto. * testing/Internals.cpp: (WebCore::Internals::address): Use makeString instead of String::format. Source/WebCore/PAL: * pal/FileSizeFormatter.cpp: (fileSizeDescription): Use makeString instead of String::format. Source/WebKit: * Platform/IPC/win/ConnectionWin.cpp: (IPC::Connection::createServerAndClientIdentifiers): Use makeString instead of String::format. * Shared/win/WebEventFactory.cpp: (WebKit::keyIdentifierFromEvent): Ditto. * UIProcess/API/APINavigation.cpp: (API::Navigation::loggingString const): Use hex instead of String::format. * UIProcess/SuspendedPageProxy.cpp: (WebKit::SuspendedPageProxy::loggingString const): Ditto. * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Added a "0x". * UIProcess/gtk/InputMethodFilter.cpp: (WebKit::InputMethodFilter::logHandleKeyboardEventForTesting): Use makeString and hex instead of String::format and "%x". (WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting): Ditto. Source/WTF: * WTF.xcodeproj/project.pbxproj: Added HexNumber.cpp and Logger.cpp. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.cpp: Added. (WTF::Internal::appendHex): Non-inline, non-template hex formatting logic. * wtf/HexNumber.h: (WTF::Internal::appendHex): Refactored main logic of appendUnsignedAsHex and appendUnsignedAsHexFixedSize so they can be reused in a function named hex for use with StringTypeAdapter. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::hex): Added. (WTF::StringTypeAdapter<HexNumberBuffer>): Added. * wtf/Logger.cpp: Added. (WTF::Logger::LogSiteIdentifier::toString const): Made this a non-template function and moved it here so that we don't need to include HexNumber.h in Logger.h. Since HexNumber.h has substantial code in it, it's good if we don't include it in any other headers. * wtf/Logger.h: (WTF::LogArgument<Logger::LogSiteIdentifier>::toString): Changed to call a non-template function, LogSiteIdentifier::toString. * wtf/text/StringConcatenateNumbers.h: Replaced overloaded writeTo functions with function templates and used StringImpl::copyCharacters instead of hand-written loops. Canonical link: https://commits.webkit.org/209182@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-19 02:04:33 +00:00
* Copyright (C) 2016-2019 Apple Inc. All rights reserved.
2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
Modern IDB: Implement native IDBFactory.getAllDatabaseNames for WebInspector. https://bugs.webkit.org/show_bug.cgi?id=157072 Reviewed by Alex Christensen. Source/WebCore: No new tests (Covered by changes to existing test). Implement a new "getAllDatabaseNames" call on IDBFactory. It is not exposed to the DOM, and is meant solely for internal WebInspector use. * Modules/indexeddb/DOMWindowIndexedDatabase.h: Export some stuff to WebCoreTestSupport * Modules/indexeddb/IDBDatabase.cpp: (WebCore::IDBDatabase::createObjectStore): * Modules/indexeddb/IDBDatabaseIdentifier.cpp: (WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot): * Modules/indexeddb/IDBDatabaseIdentifier.h: * Modules/indexeddb/IDBFactory.cpp: (WebCore::IDBFactory::getAllDatabaseNames): * Modules/indexeddb/IDBFactory.h: * Modules/indexeddb/client/IDBConnectionProxy.cpp: (WebCore::IDBClient::IDBConnectionProxy::getAllDatabaseNames): * Modules/indexeddb/client/IDBConnectionProxy.h: * Modules/indexeddb/client/IDBConnectionToServer.cpp: (WebCore::IDBClient::IDBConnectionToServer::getAllDatabaseNames): (WebCore::IDBClient::IDBConnectionToServer::didGetAllDatabaseNames): * Modules/indexeddb/client/IDBConnectionToServer.h: * Modules/indexeddb/client/IDBConnectionToServerDelegate.h: * Modules/indexeddb/server/IDBConnectionToClient.cpp: (WebCore::IDBServer::IDBConnectionToClient::didGetAllDatabaseNames): * Modules/indexeddb/server/IDBConnectionToClient.h: * Modules/indexeddb/server/IDBConnectionToClientDelegate.h: * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::getAllDatabaseNames): (WebCore::IDBServer::IDBServer::performGetAllDatabaseNames): Do the actual work of getting the appropriate directory listing and converting the paths to database names. (WebCore::IDBServer::IDBServer::didGetAllDatabaseNames): * Modules/indexeddb/server/IDBServer.h: * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp: (WebCore::IDBServer::SQLiteIDBBackingStore::databaseNameFromEncodedFilename): Helper for IDBServer. * Modules/indexeddb/server/SQLiteIDBBackingStore.h: * Modules/indexeddb/shared/InProcessIDBServer.cpp: (WebCore::InProcessIDBServer::getAllDatabaseNames): (WebCore::InProcessIDBServer::didGetAllDatabaseNames): * Modules/indexeddb/shared/InProcessIDBServer.h: * inspector/InspectorIndexedDBAgent.cpp: (WebCore::InspectorIndexedDBAgent::requestDatabaseNames): Use the new IDBFactory API to asynchronously get the list of database names. * platform/CrossThreadCopier.cpp: (WebCore::SecurityOriginData>::copy): (WebCore::Vector<String>>::copy): * platform/CrossThreadCopier.h: * platform/FileSystem.cpp: (WebCore::decodeFromFilename): Perform the reverse of encodeForFilename. * platform/FileSystem.h: * platform/cf/FileSystemCF.cpp: (WebCore::stringFromFileSystemRepresentation): * platform/glib/FileSystemGlib.cpp: (WebCore::stringFromFileSystemRepresentation): * platform/posix/FileSystemPOSIX.cpp: (WebCore::lastComponentOfPathIgnoringTrailingSlash): Utility for peeling off the last component of a multi-component path. (WebCore::listDirectory): This was broken when returning filenames with UTF in them. Fix it. * platform/mac/WebCoreNSURLExtras.mm: Move the static hex digit utility functions to WTF. (WebCore::userVisibleString): (WebCore::isUserVisibleURL): (WebCore::isHexDigit): Deleted. (WebCore::hexDigit): Deleted. (WebCore::hexDigitValue): Deleted. Source/WebKit2: Handle the process hop for the new getAllDatabaseNames call. * DatabaseProcess/IndexedDB/WebIDBConnectionToClient.cpp: (WebKit::WebIDBConnectionToClient::didGetAllDatabaseNames): (WebKit::WebIDBConnectionToClient::getAllDatabaseNames): * DatabaseProcess/IndexedDB/WebIDBConnectionToClient.h: * DatabaseProcess/IndexedDB/WebIDBConnectionToClient.messages.in: * Shared/WebCrossThreadCopier.cpp: (WebCore::SecurityOriginData>::copy): Deleted, as its in WebCore now. * Shared/WebCrossThreadCopier.h: * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp: (WebKit::WebIDBConnectionToServer::getAllDatabaseNames): (WebKit::WebIDBConnectionToServer::didGetAllDatabaseNames): * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.h: * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.messages.in: Source/WTF: Moved these Hex Digit utilities from WebCore URL code (???), and add a checked version of getting the hex digit value. * wtf/HexNumber.h: (WTF::isHexDigit): (WTF::uncheckedHexDigit): (WTF::hexDigitValue): (WTF::uncheckedHexDigitValue): LayoutTests: Add more to this test and re-enable it. * TestExpectations: * inspector/indexeddb/requestDatabaseNames-expected.txt: * inspector/indexeddb/requestDatabaseNames.html: Canonical link: https://commits.webkit.org/175216@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200163 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-04-28 01:16:28 +00:00
#pragma once
2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
Switch uses of StringBuilder with String::format for hex numbers to use HexNumber.h instead https://bugs.webkit.org/show_bug.cgi?id=194485 Reviewed by Daniel Bates. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): Use appendUnsignedAsHex along with reinterpret_cast<uintptr_t> to replace uses of String::format with "%p". * runtime/JSGlobalObjectFunctions.cpp: (JSC::encode): Removed some unneeded casts in StringBuilder code, including one in a call to appendByteAsHex. (JSC::globalFuncEscape): Ditto. Source/WebCore: * Modules/websockets/WebSocket.cpp: (WebCore::encodeProtocolString): Use appendUnsignedAsHexFixedSize instead of String::format. * css/parser/CSSParserToken.cpp: (WebCore::CSSParserToken::serialize const): Fixed style of many return statements that called a function returning void; doesn't match WebKit's prevailing style. Also use break instead of return. Used appendLiteral instead of append in many cases, and append character instead of single-character literal in others. Use appendUnsignedAsHex instead of String::format. * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: (WebCore::generateHashedName): Use appendUnsignedAsHex instad of appendUnsigned64AsHex. Should come back here and use makeString once we make HexNumber.h work with that. * platform/mac/WebCoreNSURLExtras.mm: Removed unnecessary include of HexNumber.h. * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Use appendLiteral instead of multiple calls to character append. Touched because it was next to a call to appendUnsignedAsHex. Source/WebKit: * UIProcess/DeviceIdHashSaltStorage.cpp: (WebKit::DeviceIdHashSaltStorage::completeDeviceIdHashSaltForOriginCall): Use appendUnsignedAsHex instead of appendUnsigned64AsHex. * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Use appendUnsignedAsHex and reinterpret_cast<uintptr_t> instead of String::format and "%p". Source/WTF: * wtf/HexNumber.h: Removed unused functions placeByteAsHexCompressIfPossible and placeByteAsHex. Can always bring them back if someone needs them. Updated appendUnsignedAsHex to be a template so we can use it on any integer type, got rid of unnecessary use of Vector and unnecessary reversing, and got rid of appendUnsigned64AsHex since callers can now just use appendUnsignedAsHex. Rewrote appendUnsignedAsHexFixedSize to share mode code rather than replicating. * wtf/Logger.h: Use appendUnsignedAsHex instead of appendUnsigned64AsHex. * wtf/URL.cpp: Removed unnecessary include of HexNumber.h. * wtf/cocoa/NSURLExtras.h: Added missing include of Foundation.h that was worked around in NSURLExtras.mm. * wtf/cocoa/NSURLExtras.mm: Removed unnecessary includes of HexNumber.h and Foundation.h. Tools: * WebKitTestRunner/TestController.cpp: Removed unnecessary include of HexNumber.h. Canonical link: https://commits.webkit.org/208915@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241256 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-11 06:02:05 +00:00
#include <array>
Replace multiparameter overloads of append() in StringBuilder as a first step toward standardizinging on the flexibleAppend() implementation https://bugs.webkit.org/show_bug.cgi?id=200614 Reviewed by Darin Adler. Renames StringBuilder::append(const LChar*, unsigned), StringBuilder::append(const UChar*, unsigned) and StringBuilder::append(const char*, unsigned) to StringBuilder::appendCharacters(...). Renames StringBuilder::append(const String& string, unsigned offset, unsigned length) to StringBuilder::appendSubstring(...). Source/JavaScriptCore: * dfg/DFGStrengthReductionPhase.cpp: (JSC::DFG::StrengthReductionPhase::handleNode): * runtime/ConfigFile.cpp: (JSC::ConfigFile::parse): * runtime/LiteralParser.cpp: (JSC::LiteralParser<CharType>::Lexer::lexStringSlow): * tools/FunctionOverrides.cpp: (JSC::parseClause): Update for renames. Source/WebCore: * dom/Range.cpp: (WebCore::Range::toString const): * editing/Editing.cpp: (WebCore::stringWithRebalancedWhitespace): * editing/MarkupAccumulator.cpp: (WebCore::appendCharactersReplacingEntitiesInternal): * editing/TextIterator.cpp: (WebCore::TextIteratorCopyableText::appendToStringBuilder const): * html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::valueWithHardLineBreaks const): * html/parser/HTMLTokenizer.cpp: (WebCore::HTMLTokenizer::bufferedCharacters const): * platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp: (WebCore::InbandTextTrackPrivateAVF::processNativeSamples): * platform/text/SegmentedString.cpp: (WebCore::SegmentedString::Substring::appendTo const): * platform/text/TextCodecICU.cpp: (WebCore::TextCodecICU::decode): * xml/XSLTProcessorLibxslt.cpp: (WebCore::writeToStringBuilder): Update for renames. Source/WebKit: * Shared/mac/AuxiliaryProcessMac.mm: (WebKit::setAndSerializeSandboxParameters): * UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::didReceiveInvalidMessage): Update for renames. Source/WTF: * wtf/HexNumber.h: (WTF::appendUnsignedAsHexFixedSize): Add overload that explicitly takes a StringBuilder to work around rename from append to appendCharacters. * wtf/text/StringBuilder.cpp: (WTF::StringBuilder::appendCharacters): (WTF::StringBuilder::append): * wtf/text/StringBuilder.h: (WTF::StringBuilder::appendCharacters): (WTF::StringBuilder::append): (WTF::StringBuilder::appendSubstring): (WTF::StringBuilder::appendLiteral): (WTF::IntegerToStringConversionTrait<StringBuilder>::flush): Update for renames. Tools: * TestWebKitAPI/Tests/WTF/StringBuilder.cpp: (TestWebKitAPI::TEST): Update for renames. Canonical link: https://commits.webkit.org/214401@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248552 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-08-12 23:09:06 +00:00
#include <wtf/text/StringBuilder.h>
2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
#include <wtf/text/StringConcatenate.h>
namespace WTF {
Use ASCIICType more, and improve it a little bit https://bugs.webkit.org/show_bug.cgi?id=165360 Reviewed by Sam Weinig. Source/JavaScriptCore: * inspector/InspectorValues.cpp: (Inspector::readHexDigits): Use isASCIIHexDigit. (Inspector::hextoInt): Deleted. (decodeString): Use toASCIIHexValue. * runtime/JSGlobalObjectFunctions.cpp: (JSC::parseDigit): Use isASCIIDigit, isASCIIUpper, and isASCIILower. * runtime/StringPrototype.cpp: (JSC::substituteBackreferencesSlow): Use isASCIIDigit. Source/WebCore: * css/CSSGrammar.y.in: Use isASCIIDigit. * css/parser/CSSParser.cpp: (WebCore::CSSParser::parseFontFaceUnicodeRange): Use isASCIIHexDigit and toASCIIHexValue. (WebCore::isEqualToCSSIdentifier): Use isASCIILower. * html/FormController.cpp: (WebCore::isNotFormControlTypeCharacter): Use isASCIILower. * html/parser/CSSPreloadScanner.cpp: (WebCore::CSSPreloadScanner::tokenize): Use isASCIIAlpha. * platform/Decimal.cpp: (WebCore::Decimal::fromString): Use isASCIIDigit. * platform/FileSystem.cpp: (WebCore::decodeFromFilename): Use isASCIIHexDigit and toASCIIHexValue. * platform/URL.cpp: (WebCore::isLetterMatchIgnoringCase): Deleted. (WebCore::isSchemeCharacterMatchIgnoringCase): Deleted. (WebCore::assertProtocolIsGood): Use isASCIIUpper. (WebCore::URL::protocolIs): Use isASCIIAlphaCaselessEqual. (WebCore::URL::parse): Ditto. (WebCore::protocolIs): Ditto. (WebCore::protocolIsInHTTPFamily): Ditto. * platform/URLParser.cpp: (WeCore::URLParser::parseIPv4Piece): Use isASCIIDigit. * platform/mac/WebCoreNSURLExtras.mm: (WebCore::isRussianDomainNameCharacter): Use isASCIIDigit. (WebCore::allCharactersAllowedByTLDRules): Ditto. (WebCore::dataWithUserTypedString): Use upperNibbleToASCIIHexDigit and lowerNibbleToASCIIHexDigit. (WebCore::dataForURLComponentType): Ditto. (WebCore::createStringWithEscapedUnsafeCharacters): Ditto. (WebCore::userVisibleString): Use isASCIIHexDigit, toASCIIHexValue, upperNibbleToASCIIHexDigit, and lowerNibbleToASCIIHexDigit. (WebCore::isUserVisibleURL): Use isASCIIHexDigit and toASCIIHexValue. * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): Use isASCIIAlphanumeric. * rendering/mathml/RenderMathMLToken.cpp: (WebCore::mathVariant): Use isASCIIUpper, isASCIILower, and isASCIIDigit. * svg/SVGParserUtilities.cpp: (WebCore::genericParseNumber): Use isASCIIDigit. * svg/SVGPathStringSource.cpp: (WebCore::nextCommandHelper): Ditto. * xml/XPathParser.cpp: (WebCore::XPath::Parser::lexNumber): Ditto. (WebCore::XPath::Parser::nextTokenInternal): Ditto. Source/WebKit2: * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp: (WebKit::capitalizeRFC822HeaderFieldName): Removed unneeded checks to simplify code. Source/WTF: * wtf/ASCIICType.h: Added declarations of all the functions to the top of the file, so we have a list of what's available, not just a mix of that and the implementation. * wtf/HexNumber.h: (WTF::Internal::hexDigitsForMode): Moved lowerHexDigits and upperHexDigits inside this function. (WTF::appendByteAsHex): Use auto. (WTF::placeByteAsHexCompressIfPossible): Ditto. (WTF::placeByteAsHex): Ditto. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsigned64AsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::isHexDigit): Deleted. (WTF::uncheckedHexDigit): Deleted. (WTF::hexDigitValue): Deleted. (WTF::uncheckedHexDigitValue): Deleted. * wtf/SixCharacterHash.cpp: (WTF::sixCharacterHashStringToInteger): Use isASCIIUpper, isASCIILower, and isASCIIDigit. Also added some FIXMEs; for some reason this function uses RELEASE_ASSERT to abort if the passed-in string is not six characters long, and it's not clear to me why this is so critical to assert. (WTF::integerToSixCharacterHashString): Moved the table inside this function, obviating the need for a macro named TABLE. * wtf/dtoa/bignum.cc: (WTF::double_conversion::HexCharValue): Deleted. (WTF::double_conversion::Bignum::AssignHexString): Use toASCIIHexValue. * wtf/dtoa/double-conversion.cc: (WTF::double_conversion::StringToDoubleConverter::StringToDouble): Use isASCIIDigit. * wtf/text/StringBuilder.cpp: (WTF::appendQuotedJSONStringInternal): Use upperNibbleToASCIIHexDigit and lowerNibbleToASCIIHexDigit. * wtf/text/StringImpl.cpp: (WTF::StringImpl::convertToUppercaseWithoutLocale): Use toASCIIUpper. Removed the workaround for a bug that was fixed in Visual Studio 2013. Canonical link: https://commits.webkit.org/183066@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209399 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-06 17:18:20 +00:00
enum HexConversionMode { Lowercase, Uppercase };
2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
namespace Internal {
inline const LChar* hexDigitsForMode(HexConversionMode mode)
2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
{
Use ASCIICType more, and improve it a little bit https://bugs.webkit.org/show_bug.cgi?id=165360 Reviewed by Sam Weinig. Source/JavaScriptCore: * inspector/InspectorValues.cpp: (Inspector::readHexDigits): Use isASCIIHexDigit. (Inspector::hextoInt): Deleted. (decodeString): Use toASCIIHexValue. * runtime/JSGlobalObjectFunctions.cpp: (JSC::parseDigit): Use isASCIIDigit, isASCIIUpper, and isASCIILower. * runtime/StringPrototype.cpp: (JSC::substituteBackreferencesSlow): Use isASCIIDigit. Source/WebCore: * css/CSSGrammar.y.in: Use isASCIIDigit. * css/parser/CSSParser.cpp: (WebCore::CSSParser::parseFontFaceUnicodeRange): Use isASCIIHexDigit and toASCIIHexValue. (WebCore::isEqualToCSSIdentifier): Use isASCIILower. * html/FormController.cpp: (WebCore::isNotFormControlTypeCharacter): Use isASCIILower. * html/parser/CSSPreloadScanner.cpp: (WebCore::CSSPreloadScanner::tokenize): Use isASCIIAlpha. * platform/Decimal.cpp: (WebCore::Decimal::fromString): Use isASCIIDigit. * platform/FileSystem.cpp: (WebCore::decodeFromFilename): Use isASCIIHexDigit and toASCIIHexValue. * platform/URL.cpp: (WebCore::isLetterMatchIgnoringCase): Deleted. (WebCore::isSchemeCharacterMatchIgnoringCase): Deleted. (WebCore::assertProtocolIsGood): Use isASCIIUpper. (WebCore::URL::protocolIs): Use isASCIIAlphaCaselessEqual. (WebCore::URL::parse): Ditto. (WebCore::protocolIs): Ditto. (WebCore::protocolIsInHTTPFamily): Ditto. * platform/URLParser.cpp: (WeCore::URLParser::parseIPv4Piece): Use isASCIIDigit. * platform/mac/WebCoreNSURLExtras.mm: (WebCore::isRussianDomainNameCharacter): Use isASCIIDigit. (WebCore::allCharactersAllowedByTLDRules): Ditto. (WebCore::dataWithUserTypedString): Use upperNibbleToASCIIHexDigit and lowerNibbleToASCIIHexDigit. (WebCore::dataForURLComponentType): Ditto. (WebCore::createStringWithEscapedUnsafeCharacters): Ditto. (WebCore::userVisibleString): Use isASCIIHexDigit, toASCIIHexValue, upperNibbleToASCIIHexDigit, and lowerNibbleToASCIIHexDigit. (WebCore::isUserVisibleURL): Use isASCIIHexDigit and toASCIIHexValue. * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): Use isASCIIAlphanumeric. * rendering/mathml/RenderMathMLToken.cpp: (WebCore::mathVariant): Use isASCIIUpper, isASCIILower, and isASCIIDigit. * svg/SVGParserUtilities.cpp: (WebCore::genericParseNumber): Use isASCIIDigit. * svg/SVGPathStringSource.cpp: (WebCore::nextCommandHelper): Ditto. * xml/XPathParser.cpp: (WebCore::XPath::Parser::lexNumber): Ditto. (WebCore::XPath::Parser::nextTokenInternal): Ditto. Source/WebKit2: * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp: (WebKit::capitalizeRFC822HeaderFieldName): Removed unneeded checks to simplify code. Source/WTF: * wtf/ASCIICType.h: Added declarations of all the functions to the top of the file, so we have a list of what's available, not just a mix of that and the implementation. * wtf/HexNumber.h: (WTF::Internal::hexDigitsForMode): Moved lowerHexDigits and upperHexDigits inside this function. (WTF::appendByteAsHex): Use auto. (WTF::placeByteAsHexCompressIfPossible): Ditto. (WTF::placeByteAsHex): Ditto. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsigned64AsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::isHexDigit): Deleted. (WTF::uncheckedHexDigit): Deleted. (WTF::hexDigitValue): Deleted. (WTF::uncheckedHexDigitValue): Deleted. * wtf/SixCharacterHash.cpp: (WTF::sixCharacterHashStringToInteger): Use isASCIIUpper, isASCIILower, and isASCIIDigit. Also added some FIXMEs; for some reason this function uses RELEASE_ASSERT to abort if the passed-in string is not six characters long, and it's not clear to me why this is so critical to assert. (WTF::integerToSixCharacterHashString): Moved the table inside this function, obviating the need for a macro named TABLE. * wtf/dtoa/bignum.cc: (WTF::double_conversion::HexCharValue): Deleted. (WTF::double_conversion::Bignum::AssignHexString): Use toASCIIHexValue. * wtf/dtoa/double-conversion.cc: (WTF::double_conversion::StringToDoubleConverter::StringToDouble): Use isASCIIDigit. * wtf/text/StringBuilder.cpp: (WTF::appendQuotedJSONStringInternal): Use upperNibbleToASCIIHexDigit and lowerNibbleToASCIIHexDigit. * wtf/text/StringImpl.cpp: (WTF::StringImpl::convertToUppercaseWithoutLocale): Use toASCIIUpper. Removed the workaround for a bug that was fixed in Visual Studio 2013. Canonical link: https://commits.webkit.org/183066@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209399 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-06 17:18:20 +00:00
static const LChar lowercaseHexDigits[17] = "0123456789abcdef";
static const LChar uppercaseHexDigits[17] = "0123456789ABCDEF";
return mode == Lowercase ? lowercaseHexDigits : uppercaseHexDigits;
2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
}
WTF_EXPORT_PRIVATE std::pair<LChar*, unsigned> appendHex(LChar* buffer, unsigned bufferSize, std::uintmax_t number, unsigned minimumDigits, HexConversionMode);
Continue reducing use of String::format, now focusing on hex: "%p", "%x", etc. https://bugs.webkit.org/show_bug.cgi?id=194752 Reviewed by Daniel Bates. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): Added back the "0x" that was removed when changing this file to use appendUnsignedAsHex instead of "%p". The intent at that time was to keep behavior the same, so let's do that. * parser/Lexer.cpp: (JSC::Lexer<T>::invalidCharacterMessage const): Use makeString and hex instead of String::format and "%04x". Source/WebCore: * Modules/websockets/WebSocket.cpp: Added an include of HexNumber.h. This previously got included because of Logger.h, but that no longer pulls in HexNumber.h. * css/CSSMarkup.cpp: Removed unneeded include of StringBuffer.h. * css/CSSPrimitiveValue.cpp: Ditto. * css/CSSUnicodeRangeValue.cpp: (WebCore::CSSUnicodeRangeValue::customCSSText const): Use makeString and hex instead of String::format and "%x". * html/HTMLMediaElement.h: (WTF::ValueToString<WebCore::TextTrackCue::string): Use a non-template function, TextTrackCure::debugString, so we don't need to use HextNumber.h in a header. * html/canvas/WebGLRenderingContextBase.cpp: (GetErrorString): Use makeString and hex instead of String::format and "%04x". * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::debugString const): Added. Moved string conversion here from HTMLMediaElement.h and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * html/track/TextTrackCue.h: Added TextTrackCue::debugString. * page/linux/ResourceUsageOverlayLinux.cpp: (WebCore::formatByteNumber): Use makeString and FormattedNumber::fixedWidth instead of String::format and "%.1f" etc. * platform/cocoa/KeyEventCocoa.mm: (WebCore::keyIdentifierForCharCode): Use the new hex function here instead of the old code that did each of the four characters explicitly. * platform/gamepad/mac/HIDGamepad.cpp: (WebCore::HIDGamepad::HIDGamepad): Use makeString instead of String::format. * platform/graphics/Color.cpp: (WebCore::Color::nameForRenderTreeAsText const): Use hex instead of doing each digit separately. * platform/graphics/FloatPolygon.cpp: (WebCore::FloatPolygonEdge::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * platform/graphics/FloatPolygon.h: Updated for the above. * platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::GraphicsLayerCA::setName): Use makeString instead of String::format. (WebCore::GraphicsLayerCA::recursiveCommitChanges): DItto. * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::load): Ditto. (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Ditto. * platform/gtk/PlatformKeyboardEventGtk.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForGdkKeyCode): Ditto. * platform/libwpe/PlatformKeyboardEventLibWPE.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForWPEKeyCode): Ditto. * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: (WebCore::GStreamerVideoEncoder::makeElement): Ditto. (WebCore::GStreamerVideoEncoder::InitEncode): Ditto. * platform/text/TextCodecLatin1.cpp: Removed unneeded include of StringBuffer.h and "using namespace WTF". * platform/win/GDIObjectCounter.cpp: (WebCore::GDIObjectCounter::GDIObjectCounter): Use makeString instead of String::format. * platform/win/KeyEventWin.cpp: (WebCore::keyIdentifierForWindowsKeyCode): Ditto. * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/FloatingObjects.h: Updated for the above. * rendering/RenderFragmentContainer.cpp: (WebCore::RenderFragmentContainer::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/RenderFragmentContainer.h: Updated for the above. * rendering/RenderFragmentedFlow.h: Ditto. * testing/Internals.cpp: (WebCore::Internals::address): Use makeString instead of String::format. Source/WebCore/PAL: * pal/FileSizeFormatter.cpp: (fileSizeDescription): Use makeString instead of String::format. Source/WebKit: * Platform/IPC/win/ConnectionWin.cpp: (IPC::Connection::createServerAndClientIdentifiers): Use makeString instead of String::format. * Shared/win/WebEventFactory.cpp: (WebKit::keyIdentifierFromEvent): Ditto. * UIProcess/API/APINavigation.cpp: (API::Navigation::loggingString const): Use hex instead of String::format. * UIProcess/SuspendedPageProxy.cpp: (WebKit::SuspendedPageProxy::loggingString const): Ditto. * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Added a "0x". * UIProcess/gtk/InputMethodFilter.cpp: (WebKit::InputMethodFilter::logHandleKeyboardEventForTesting): Use makeString and hex instead of String::format and "%x". (WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting): Ditto. Source/WTF: * WTF.xcodeproj/project.pbxproj: Added HexNumber.cpp and Logger.cpp. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.cpp: Added. (WTF::Internal::appendHex): Non-inline, non-template hex formatting logic. * wtf/HexNumber.h: (WTF::Internal::appendHex): Refactored main logic of appendUnsignedAsHex and appendUnsignedAsHexFixedSize so they can be reused in a function named hex for use with StringTypeAdapter. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::hex): Added. (WTF::StringTypeAdapter<HexNumberBuffer>): Added. * wtf/Logger.cpp: Added. (WTF::Logger::LogSiteIdentifier::toString const): Made this a non-template function and moved it here so that we don't need to include HexNumber.h in Logger.h. Since HexNumber.h has substantial code in it, it's good if we don't include it in any other headers. * wtf/Logger.h: (WTF::LogArgument<Logger::LogSiteIdentifier>::toString): Changed to call a non-template function, LogSiteIdentifier::toString. * wtf/text/StringConcatenateNumbers.h: Replaced overloaded writeTo functions with function templates and used StringImpl::copyCharacters instead of hand-written loops. Canonical link: https://commits.webkit.org/209182@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-19 02:04:33 +00:00
template<size_t arraySize, typename NumberType>
inline std::pair<LChar*, unsigned> appendHex(std::array<LChar, arraySize>& buffer, NumberType number, unsigned minimumDigits, HexConversionMode mode)
{
return appendHex(&buffer.front(), buffer.size(), static_cast<typename std::make_unsigned<NumberType>::type>(number), minimumDigits, mode);
}
Use ASCIICType more, and improve it a little bit https://bugs.webkit.org/show_bug.cgi?id=165360 Reviewed by Sam Weinig. Source/JavaScriptCore: * inspector/InspectorValues.cpp: (Inspector::readHexDigits): Use isASCIIHexDigit. (Inspector::hextoInt): Deleted. (decodeString): Use toASCIIHexValue. * runtime/JSGlobalObjectFunctions.cpp: (JSC::parseDigit): Use isASCIIDigit, isASCIIUpper, and isASCIILower. * runtime/StringPrototype.cpp: (JSC::substituteBackreferencesSlow): Use isASCIIDigit. Source/WebCore: * css/CSSGrammar.y.in: Use isASCIIDigit. * css/parser/CSSParser.cpp: (WebCore::CSSParser::parseFontFaceUnicodeRange): Use isASCIIHexDigit and toASCIIHexValue. (WebCore::isEqualToCSSIdentifier): Use isASCIILower. * html/FormController.cpp: (WebCore::isNotFormControlTypeCharacter): Use isASCIILower. * html/parser/CSSPreloadScanner.cpp: (WebCore::CSSPreloadScanner::tokenize): Use isASCIIAlpha. * platform/Decimal.cpp: (WebCore::Decimal::fromString): Use isASCIIDigit. * platform/FileSystem.cpp: (WebCore::decodeFromFilename): Use isASCIIHexDigit and toASCIIHexValue. * platform/URL.cpp: (WebCore::isLetterMatchIgnoringCase): Deleted. (WebCore::isSchemeCharacterMatchIgnoringCase): Deleted. (WebCore::assertProtocolIsGood): Use isASCIIUpper. (WebCore::URL::protocolIs): Use isASCIIAlphaCaselessEqual. (WebCore::URL::parse): Ditto. (WebCore::protocolIs): Ditto. (WebCore::protocolIsInHTTPFamily): Ditto. * platform/URLParser.cpp: (WeCore::URLParser::parseIPv4Piece): Use isASCIIDigit. * platform/mac/WebCoreNSURLExtras.mm: (WebCore::isRussianDomainNameCharacter): Use isASCIIDigit. (WebCore::allCharactersAllowedByTLDRules): Ditto. (WebCore::dataWithUserTypedString): Use upperNibbleToASCIIHexDigit and lowerNibbleToASCIIHexDigit. (WebCore::dataForURLComponentType): Ditto. (WebCore::createStringWithEscapedUnsafeCharacters): Ditto. (WebCore::userVisibleString): Use isASCIIHexDigit, toASCIIHexValue, upperNibbleToASCIIHexDigit, and lowerNibbleToASCIIHexDigit. (WebCore::isUserVisibleURL): Use isASCIIHexDigit and toASCIIHexValue. * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): Use isASCIIAlphanumeric. * rendering/mathml/RenderMathMLToken.cpp: (WebCore::mathVariant): Use isASCIIUpper, isASCIILower, and isASCIIDigit. * svg/SVGParserUtilities.cpp: (WebCore::genericParseNumber): Use isASCIIDigit. * svg/SVGPathStringSource.cpp: (WebCore::nextCommandHelper): Ditto. * xml/XPathParser.cpp: (WebCore::XPath::Parser::lexNumber): Ditto. (WebCore::XPath::Parser::nextTokenInternal): Ditto. Source/WebKit2: * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp: (WebKit::capitalizeRFC822HeaderFieldName): Removed unneeded checks to simplify code. Source/WTF: * wtf/ASCIICType.h: Added declarations of all the functions to the top of the file, so we have a list of what's available, not just a mix of that and the implementation. * wtf/HexNumber.h: (WTF::Internal::hexDigitsForMode): Moved lowerHexDigits and upperHexDigits inside this function. (WTF::appendByteAsHex): Use auto. (WTF::placeByteAsHexCompressIfPossible): Ditto. (WTF::placeByteAsHex): Ditto. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsigned64AsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::isHexDigit): Deleted. (WTF::uncheckedHexDigit): Deleted. (WTF::hexDigitValue): Deleted. (WTF::uncheckedHexDigitValue): Deleted. * wtf/SixCharacterHash.cpp: (WTF::sixCharacterHashStringToInteger): Use isASCIIUpper, isASCIILower, and isASCIIDigit. Also added some FIXMEs; for some reason this function uses RELEASE_ASSERT to abort if the passed-in string is not six characters long, and it's not clear to me why this is so critical to assert. (WTF::integerToSixCharacterHashString): Moved the table inside this function, obviating the need for a macro named TABLE. * wtf/dtoa/bignum.cc: (WTF::double_conversion::HexCharValue): Deleted. (WTF::double_conversion::Bignum::AssignHexString): Use toASCIIHexValue. * wtf/dtoa/double-conversion.cc: (WTF::double_conversion::StringToDoubleConverter::StringToDouble): Use isASCIIDigit. * wtf/text/StringBuilder.cpp: (WTF::appendQuotedJSONStringInternal): Use upperNibbleToASCIIHexDigit and lowerNibbleToASCIIHexDigit. * wtf/text/StringImpl.cpp: (WTF::StringImpl::convertToUppercaseWithoutLocale): Use toASCIIUpper. Removed the workaround for a bug that was fixed in Visual Studio 2013. Canonical link: https://commits.webkit.org/183066@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209399 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-06 17:18:20 +00:00
} // namespace Internal
2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
Continue reducing use of String::format, now focusing on hex: "%p", "%x", etc. https://bugs.webkit.org/show_bug.cgi?id=194752 Reviewed by Daniel Bates. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): Added back the "0x" that was removed when changing this file to use appendUnsignedAsHex instead of "%p". The intent at that time was to keep behavior the same, so let's do that. * parser/Lexer.cpp: (JSC::Lexer<T>::invalidCharacterMessage const): Use makeString and hex instead of String::format and "%04x". Source/WebCore: * Modules/websockets/WebSocket.cpp: Added an include of HexNumber.h. This previously got included because of Logger.h, but that no longer pulls in HexNumber.h. * css/CSSMarkup.cpp: Removed unneeded include of StringBuffer.h. * css/CSSPrimitiveValue.cpp: Ditto. * css/CSSUnicodeRangeValue.cpp: (WebCore::CSSUnicodeRangeValue::customCSSText const): Use makeString and hex instead of String::format and "%x". * html/HTMLMediaElement.h: (WTF::ValueToString<WebCore::TextTrackCue::string): Use a non-template function, TextTrackCure::debugString, so we don't need to use HextNumber.h in a header. * html/canvas/WebGLRenderingContextBase.cpp: (GetErrorString): Use makeString and hex instead of String::format and "%04x". * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::debugString const): Added. Moved string conversion here from HTMLMediaElement.h and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * html/track/TextTrackCue.h: Added TextTrackCue::debugString. * page/linux/ResourceUsageOverlayLinux.cpp: (WebCore::formatByteNumber): Use makeString and FormattedNumber::fixedWidth instead of String::format and "%.1f" etc. * platform/cocoa/KeyEventCocoa.mm: (WebCore::keyIdentifierForCharCode): Use the new hex function here instead of the old code that did each of the four characters explicitly. * platform/gamepad/mac/HIDGamepad.cpp: (WebCore::HIDGamepad::HIDGamepad): Use makeString instead of String::format. * platform/graphics/Color.cpp: (WebCore::Color::nameForRenderTreeAsText const): Use hex instead of doing each digit separately. * platform/graphics/FloatPolygon.cpp: (WebCore::FloatPolygonEdge::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * platform/graphics/FloatPolygon.h: Updated for the above. * platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::GraphicsLayerCA::setName): Use makeString instead of String::format. (WebCore::GraphicsLayerCA::recursiveCommitChanges): DItto. * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::load): Ditto. (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Ditto. * platform/gtk/PlatformKeyboardEventGtk.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForGdkKeyCode): Ditto. * platform/libwpe/PlatformKeyboardEventLibWPE.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForWPEKeyCode): Ditto. * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: (WebCore::GStreamerVideoEncoder::makeElement): Ditto. (WebCore::GStreamerVideoEncoder::InitEncode): Ditto. * platform/text/TextCodecLatin1.cpp: Removed unneeded include of StringBuffer.h and "using namespace WTF". * platform/win/GDIObjectCounter.cpp: (WebCore::GDIObjectCounter::GDIObjectCounter): Use makeString instead of String::format. * platform/win/KeyEventWin.cpp: (WebCore::keyIdentifierForWindowsKeyCode): Ditto. * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/FloatingObjects.h: Updated for the above. * rendering/RenderFragmentContainer.cpp: (WebCore::RenderFragmentContainer::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/RenderFragmentContainer.h: Updated for the above. * rendering/RenderFragmentedFlow.h: Ditto. * testing/Internals.cpp: (WebCore::Internals::address): Use makeString instead of String::format. Source/WebCore/PAL: * pal/FileSizeFormatter.cpp: (fileSizeDescription): Use makeString instead of String::format. Source/WebKit: * Platform/IPC/win/ConnectionWin.cpp: (IPC::Connection::createServerAndClientIdentifiers): Use makeString instead of String::format. * Shared/win/WebEventFactory.cpp: (WebKit::keyIdentifierFromEvent): Ditto. * UIProcess/API/APINavigation.cpp: (API::Navigation::loggingString const): Use hex instead of String::format. * UIProcess/SuspendedPageProxy.cpp: (WebKit::SuspendedPageProxy::loggingString const): Ditto. * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Added a "0x". * UIProcess/gtk/InputMethodFilter.cpp: (WebKit::InputMethodFilter::logHandleKeyboardEventForTesting): Use makeString and hex instead of String::format and "%x". (WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting): Ditto. Source/WTF: * WTF.xcodeproj/project.pbxproj: Added HexNumber.cpp and Logger.cpp. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.cpp: Added. (WTF::Internal::appendHex): Non-inline, non-template hex formatting logic. * wtf/HexNumber.h: (WTF::Internal::appendHex): Refactored main logic of appendUnsignedAsHex and appendUnsignedAsHexFixedSize so they can be reused in a function named hex for use with StringTypeAdapter. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::hex): Added. (WTF::StringTypeAdapter<HexNumberBuffer>): Added. * wtf/Logger.cpp: Added. (WTF::Logger::LogSiteIdentifier::toString const): Made this a non-template function and moved it here so that we don't need to include HexNumber.h in Logger.h. Since HexNumber.h has substantial code in it, it's good if we don't include it in any other headers. * wtf/Logger.h: (WTF::LogArgument<Logger::LogSiteIdentifier>::toString): Changed to call a non-template function, LogSiteIdentifier::toString. * wtf/text/StringConcatenateNumbers.h: Replaced overloaded writeTo functions with function templates and used StringImpl::copyCharacters instead of hand-written loops. Canonical link: https://commits.webkit.org/209182@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-19 02:04:33 +00:00
struct HexNumberBuffer {
[WTF][JSC] Make JSC and WTF aggressively-fast-malloced https://bugs.webkit.org/show_bug.cgi?id=200611 Reviewed by Saam Barati. Source/JavaScriptCore: This patch aggressively puts many classes into FastMalloc. In JSC side, we grep `std::make_unique` etc. to find potentially system-malloc-allocated classes. After this patch, all the JSC related allocations in JetStream2 cli is done from bmalloc. In the future, it would be nice that we add `WTF::makeUnique<T>` helper function and throw a compile error if `T` is not FastMalloc annotated[1]. Putting WebKit classes in FastMalloc has many benefits. 1. Simply, it is fast. 2. vmmap can tell the amount of memory used for WebKit. 3. bmalloc can isolate WebKit memory allocation from the rest of the world. This is useful since we can know more about what component is corrupting the memory from the memory corruption crash. [1]: https://bugs.webkit.org/show_bug.cgi?id=200620 * API/ObjCCallbackFunction.mm: * assembler/AbstractMacroAssembler.h: * b3/B3PhiChildren.h: * b3/air/AirAllocateRegistersAndStackAndGenerateCode.h: * b3/air/AirDisassembler.h: * bytecode/AccessCaseSnippetParams.h: * bytecode/CallVariant.h: * bytecode/DeferredSourceDump.h: * bytecode/ExecutionCounter.h: * bytecode/GetByIdStatus.h: * bytecode/GetByIdVariant.h: * bytecode/InByIdStatus.h: * bytecode/InByIdVariant.h: * bytecode/InstanceOfStatus.h: * bytecode/InstanceOfVariant.h: * bytecode/PutByIdStatus.h: * bytecode/PutByIdVariant.h: * bytecode/ValueProfile.h: * dfg/DFGAbstractInterpreter.h: * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::newVariableAccessData): * dfg/DFGFlowIndexing.h: * dfg/DFGFlowMap.h: * dfg/DFGLiveCatchVariablePreservationPhase.cpp: (JSC::DFG::LiveCatchVariablePreservationPhase::newVariableAccessData): * dfg/DFGMaximalFlushInsertionPhase.cpp: (JSC::DFG::MaximalFlushInsertionPhase::newVariableAccessData): * dfg/DFGOSRExit.h: * dfg/DFGSpeculativeJIT.h: * dfg/DFGVariableAccessData.h: * disassembler/ARM64/A64DOpcode.h: * inspector/remote/socket/RemoteInspectorMessageParser.h: * inspector/remote/socket/RemoteInspectorSocket.h: * inspector/remote/socket/RemoteInspectorSocketEndpoint.h: * jit/PCToCodeOriginMap.h: * runtime/BasicBlockLocation.h: * runtime/DoublePredictionFuzzerAgent.h: * runtime/JSRunLoopTimer.h: * runtime/PromiseDeferredTimer.h: (JSC::PromiseDeferredTimer::create): PromiseDeferredTimer should be allocated as `Ref<>` instead of `std::unique_ptr` since it is inheriting ThreadSafeRefCounted<>. Holding such a class with std::unique_ptr could lead to potentially dangerous operations (like, someone holds it with Ref<> while it is deleted by std::unique_ptr<>). * runtime/RandomizingFuzzerAgent.h: * runtime/SymbolTable.h: * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: * tools/JSDollarVM.cpp: * tools/SigillCrashAnalyzer.cpp: * wasm/WasmFormat.h: * wasm/WasmMemory.cpp: * wasm/WasmSignature.h: * yarr/YarrJIT.h: Source/WebCore: Changed the accessor since we changed std::unique_ptr to Ref for this field. No behavior change. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::addTimerSetNotification): (WebCore::WorkerScriptController::removeTimerSetNotification): Source/WTF: WTF has many data structures, in particular, containers. And these containers can be allocated like `std::make_unique<Container>()`. Without WTF_MAKE_FAST_ALLOCATED, this container itself is allocated from the system malloc. This patch attaches WTF_MAKE_FAST_ALLOCATED more aggressively not to allocate them from the system malloc. And we add some `final` to containers and classes that would be never inherited. * wtf/Assertions.cpp: * wtf/Atomics.h: * wtf/AutodrainedPool.h: * wtf/Bag.h: (WTF::Bag::Bag): Deleted. (WTF::Bag::~Bag): Deleted. (WTF::Bag::clear): Deleted. (WTF::Bag::add): Deleted. (WTF::Bag::iterator::iterator): Deleted. (WTF::Bag::iterator::operator! const): Deleted. (WTF::Bag::iterator::operator* const): Deleted. (WTF::Bag::iterator::operator++): Deleted. (WTF::Bag::iterator::operator== const): Deleted. (WTF::Bag::iterator::operator!= const): Deleted. (WTF::Bag::begin): Deleted. (WTF::Bag::begin const): Deleted. (WTF::Bag::end const): Deleted. (WTF::Bag::isEmpty const): Deleted. (WTF::Bag::unwrappedHead const): Deleted. * wtf/BitVector.h: (WTF::BitVector::BitVector): Deleted. (WTF::BitVector::~BitVector): Deleted. (WTF::BitVector::operator=): Deleted. (WTF::BitVector::size const): Deleted. (WTF::BitVector::ensureSize): Deleted. (WTF::BitVector::quickGet const): Deleted. (WTF::BitVector::quickSet): Deleted. (WTF::BitVector::quickClear): Deleted. (WTF::BitVector::get const): Deleted. (WTF::BitVector::contains const): Deleted. (WTF::BitVector::set): Deleted. (WTF::BitVector::add): Deleted. (WTF::BitVector::ensureSizeAndSet): Deleted. (WTF::BitVector::clear): Deleted. (WTF::BitVector::remove): Deleted. (WTF::BitVector::merge): Deleted. (WTF::BitVector::filter): Deleted. (WTF::BitVector::exclude): Deleted. (WTF::BitVector::bitCount const): Deleted. (WTF::BitVector::isEmpty const): Deleted. (WTF::BitVector::findBit const): Deleted. (WTF::BitVector::isEmptyValue const): Deleted. (WTF::BitVector::isDeletedValue const): Deleted. (WTF::BitVector::isEmptyOrDeletedValue const): Deleted. (WTF::BitVector::operator== const): Deleted. (WTF::BitVector::hash const): Deleted. (WTF::BitVector::iterator::iterator): Deleted. (WTF::BitVector::iterator::operator* const): Deleted. (WTF::BitVector::iterator::operator++): Deleted. (WTF::BitVector::iterator::isAtEnd const): Deleted. (WTF::BitVector::iterator::operator== const): Deleted. (WTF::BitVector::iterator::operator!= const): Deleted. (WTF::BitVector::begin const): Deleted. (WTF::BitVector::end const): Deleted. (WTF::BitVector::bitsInPointer): Deleted. (WTF::BitVector::maxInlineBits): Deleted. (WTF::BitVector::byteCount): Deleted. (WTF::BitVector::makeInlineBits): Deleted. (WTF::BitVector::cleanseInlineBits): Deleted. (WTF::BitVector::bitCount): Deleted. (WTF::BitVector::findBitFast const): Deleted. (WTF::BitVector::findBitSimple const): Deleted. (WTF::BitVector::OutOfLineBits::numBits const): Deleted. (WTF::BitVector::OutOfLineBits::numWords const): Deleted. (WTF::BitVector::OutOfLineBits::bits): Deleted. (WTF::BitVector::OutOfLineBits::bits const): Deleted. (WTF::BitVector::OutOfLineBits::OutOfLineBits): Deleted. (WTF::BitVector::isInline const): Deleted. (WTF::BitVector::outOfLineBits const): Deleted. (WTF::BitVector::outOfLineBits): Deleted. (WTF::BitVector::bits): Deleted. (WTF::BitVector::bits const): Deleted. * wtf/Bitmap.h: (WTF::Bitmap::size): Deleted. (WTF::Bitmap::iterator::iterator): Deleted. (WTF::Bitmap::iterator::operator* const): Deleted. (WTF::Bitmap::iterator::operator++): Deleted. (WTF::Bitmap::iterator::operator== const): Deleted. (WTF::Bitmap::iterator::operator!= const): Deleted. (WTF::Bitmap::begin const): Deleted. (WTF::Bitmap::end const): Deleted. * wtf/Box.h: * wtf/BumpPointerAllocator.h: * wtf/CPUTime.h: * wtf/CheckedBoolean.h: * wtf/CommaPrinter.h: (WTF::CommaPrinter::CommaPrinter): Deleted. (WTF::CommaPrinter::dump const): Deleted. (WTF::CommaPrinter::didPrint const): Deleted. * wtf/CompactPointerTuple.h: (WTF::CompactPointerTuple::encodeType): Deleted. (WTF::CompactPointerTuple::decodeType): Deleted. (WTF::CompactPointerTuple::CompactPointerTuple): Deleted. (WTF::CompactPointerTuple::pointer const): Deleted. (WTF::CompactPointerTuple::setPointer): Deleted. (WTF::CompactPointerTuple::type const): Deleted. (WTF::CompactPointerTuple::setType): Deleted. * wtf/CompilationThread.h: (WTF::CompilationScope::CompilationScope): Deleted. (WTF::CompilationScope::~CompilationScope): Deleted. (WTF::CompilationScope::leaveEarly): Deleted. * wtf/CompletionHandler.h: (WTF::CompletionHandler<Out): (WTF::Detail::CallableWrapper<CompletionHandler<Out): (WTF::CompletionHandlerCallingScope::CompletionHandlerCallingScope): Deleted. (WTF::CompletionHandlerCallingScope::~CompletionHandlerCallingScope): Deleted. (WTF::CompletionHandlerCallingScope::CompletionHandler<void): Deleted. * wtf/ConcurrentBuffer.h: (WTF::ConcurrentBuffer::ConcurrentBuffer): Deleted. (WTF::ConcurrentBuffer::~ConcurrentBuffer): Deleted. (WTF::ConcurrentBuffer::growExact): Deleted. (WTF::ConcurrentBuffer::grow): Deleted. (WTF::ConcurrentBuffer::array const): Deleted. (WTF::ConcurrentBuffer::operator[]): Deleted. (WTF::ConcurrentBuffer::operator[] const): Deleted. (WTF::ConcurrentBuffer::createArray): Deleted. * wtf/ConcurrentPtrHashSet.h: (WTF::ConcurrentPtrHashSet::contains): Deleted. (WTF::ConcurrentPtrHashSet::add): Deleted. (WTF::ConcurrentPtrHashSet::size const): Deleted. (WTF::ConcurrentPtrHashSet::Table::maxLoad const): Deleted. (WTF::ConcurrentPtrHashSet::hash): Deleted. (WTF::ConcurrentPtrHashSet::cast): Deleted. (WTF::ConcurrentPtrHashSet::containsImpl const): Deleted. (WTF::ConcurrentPtrHashSet::addImpl): Deleted. * wtf/ConcurrentVector.h: (WTF::ConcurrentVector::~ConcurrentVector): Deleted. (WTF::ConcurrentVector::size const): Deleted. (WTF::ConcurrentVector::isEmpty const): Deleted. (WTF::ConcurrentVector::at): Deleted. (WTF::ConcurrentVector::at const): Deleted. (WTF::ConcurrentVector::operator[]): Deleted. (WTF::ConcurrentVector::operator[] const): Deleted. (WTF::ConcurrentVector::first): Deleted. (WTF::ConcurrentVector::first const): Deleted. (WTF::ConcurrentVector::last): Deleted. (WTF::ConcurrentVector::last const): Deleted. (WTF::ConcurrentVector::takeLast): Deleted. (WTF::ConcurrentVector::append): Deleted. (WTF::ConcurrentVector::alloc): Deleted. (WTF::ConcurrentVector::removeLast): Deleted. (WTF::ConcurrentVector::grow): Deleted. (WTF::ConcurrentVector::begin): Deleted. (WTF::ConcurrentVector::end): Deleted. (WTF::ConcurrentVector::segmentExistsFor): Deleted. (WTF::ConcurrentVector::segmentFor): Deleted. (WTF::ConcurrentVector::subscriptFor): Deleted. (WTF::ConcurrentVector::ensureSegmentsFor): Deleted. (WTF::ConcurrentVector::ensureSegment): Deleted. (WTF::ConcurrentVector::allocateSegment): Deleted. * wtf/Condition.h: (WTF::Condition::waitUntil): Deleted. (WTF::Condition::waitFor): Deleted. (WTF::Condition::wait): Deleted. (WTF::Condition::notifyOne): Deleted. (WTF::Condition::notifyAll): Deleted. * wtf/CountingLock.h: (WTF::CountingLock::LockHooks::lockHook): Deleted. (WTF::CountingLock::LockHooks::unlockHook): Deleted. (WTF::CountingLock::LockHooks::parkHook): Deleted. (WTF::CountingLock::LockHooks::handoffHook): Deleted. (WTF::CountingLock::tryLock): Deleted. (WTF::CountingLock::lock): Deleted. (WTF::CountingLock::unlock): Deleted. (WTF::CountingLock::isHeld const): Deleted. (WTF::CountingLock::isLocked const): Deleted. (WTF::CountingLock::Count::operator bool const): Deleted. (WTF::CountingLock::Count::operator== const): Deleted. (WTF::CountingLock::Count::operator!= const): Deleted. (WTF::CountingLock::tryOptimisticRead): Deleted. (WTF::CountingLock::validate): Deleted. (WTF::CountingLock::doOptimizedRead): Deleted. (WTF::CountingLock::tryOptimisticFencelessRead): Deleted. (WTF::CountingLock::fencelessValidate): Deleted. (WTF::CountingLock::doOptimizedFencelessRead): Deleted. (WTF::CountingLock::getCount): Deleted. * wtf/CrossThreadQueue.h: * wtf/CrossThreadTask.h: * wtf/CryptographicallyRandomNumber.cpp: * wtf/DataMutex.h: * wtf/DateMath.h: * wtf/Deque.h: (WTF::Deque::size const): Deleted. (WTF::Deque::isEmpty const): Deleted. (WTF::Deque::begin): Deleted. (WTF::Deque::end): Deleted. (WTF::Deque::begin const): Deleted. (WTF::Deque::end const): Deleted. (WTF::Deque::rbegin): Deleted. (WTF::Deque::rend): Deleted. (WTF::Deque::rbegin const): Deleted. (WTF::Deque::rend const): Deleted. (WTF::Deque::first): Deleted. (WTF::Deque::first const): Deleted. (WTF::Deque::last): Deleted. (WTF::Deque::last const): Deleted. (WTF::Deque::append): Deleted. * wtf/Dominators.h: * wtf/DoublyLinkedList.h: * wtf/Expected.h: * wtf/FastBitVector.h: * wtf/FileMetadata.h: * wtf/FileSystem.h: * wtf/GraphNodeWorklist.h: * wtf/GregorianDateTime.h: (WTF::GregorianDateTime::GregorianDateTime): Deleted. (WTF::GregorianDateTime::year const): Deleted. (WTF::GregorianDateTime::month const): Deleted. (WTF::GregorianDateTime::yearDay const): Deleted. (WTF::GregorianDateTime::monthDay const): Deleted. (WTF::GregorianDateTime::weekDay const): Deleted. (WTF::GregorianDateTime::hour const): Deleted. (WTF::GregorianDateTime::minute const): Deleted. (WTF::GregorianDateTime::second const): Deleted. (WTF::GregorianDateTime::utcOffset const): Deleted. (WTF::GregorianDateTime::isDST const): Deleted. (WTF::GregorianDateTime::setYear): Deleted. (WTF::GregorianDateTime::setMonth): Deleted. (WTF::GregorianDateTime::setYearDay): Deleted. (WTF::GregorianDateTime::setMonthDay): Deleted. (WTF::GregorianDateTime::setWeekDay): Deleted. (WTF::GregorianDateTime::setHour): Deleted. (WTF::GregorianDateTime::setMinute): Deleted. (WTF::GregorianDateTime::setSecond): Deleted. (WTF::GregorianDateTime::setUtcOffset): Deleted. (WTF::GregorianDateTime::setIsDST): Deleted. (WTF::GregorianDateTime::operator tm const): Deleted. (WTF::GregorianDateTime::copyFrom): Deleted. * wtf/HashTable.h: * wtf/Hasher.h: * wtf/HexNumber.h: * wtf/Indenter.h: * wtf/IndexMap.h: * wtf/IndexSet.h: * wtf/IndexSparseSet.h: * wtf/IndexedContainerIterator.h: * wtf/Insertion.h: * wtf/IteratorAdaptors.h: * wtf/IteratorRange.h: * wtf/KeyValuePair.h: * wtf/ListHashSet.h: (WTF::ListHashSet::begin): Deleted. (WTF::ListHashSet::end): Deleted. (WTF::ListHashSet::begin const): Deleted. (WTF::ListHashSet::end const): Deleted. (WTF::ListHashSet::random): Deleted. (WTF::ListHashSet::random const): Deleted. (WTF::ListHashSet::rbegin): Deleted. (WTF::ListHashSet::rend): Deleted. (WTF::ListHashSet::rbegin const): Deleted. (WTF::ListHashSet::rend const): Deleted. * wtf/Liveness.h: * wtf/LocklessBag.h: (WTF::LocklessBag::LocklessBag): Deleted. (WTF::LocklessBag::add): Deleted. (WTF::LocklessBag::iterate): Deleted. (WTF::LocklessBag::consumeAll): Deleted. (WTF::LocklessBag::consumeAllWithNode): Deleted. (WTF::LocklessBag::~LocklessBag): Deleted. * wtf/LoggingHashID.h: * wtf/MD5.h: * wtf/MachSendRight.h: * wtf/MainThreadData.h: * wtf/Markable.h: * wtf/MediaTime.h: * wtf/MemoryPressureHandler.h: * wtf/MessageQueue.h: (WTF::MessageQueue::MessageQueue): Deleted. * wtf/MetaAllocator.h: * wtf/MonotonicTime.h: (WTF::MonotonicTime::MonotonicTime): Deleted. (WTF::MonotonicTime::fromRawSeconds): Deleted. (WTF::MonotonicTime::infinity): Deleted. (WTF::MonotonicTime::nan): Deleted. (WTF::MonotonicTime::secondsSinceEpoch const): Deleted. (WTF::MonotonicTime::approximateMonotonicTime const): Deleted. (WTF::MonotonicTime::operator bool const): Deleted. (WTF::MonotonicTime::operator+ const): Deleted. (WTF::MonotonicTime::operator- const): Deleted. (WTF::MonotonicTime::operator% const): Deleted. (WTF::MonotonicTime::operator+=): Deleted. (WTF::MonotonicTime::operator-=): Deleted. (WTF::MonotonicTime::operator== const): Deleted. (WTF::MonotonicTime::operator!= const): Deleted. (WTF::MonotonicTime::operator< const): Deleted. (WTF::MonotonicTime::operator> const): Deleted. (WTF::MonotonicTime::operator<= const): Deleted. (WTF::MonotonicTime::operator>= const): Deleted. (WTF::MonotonicTime::isolatedCopy const): Deleted. (WTF::MonotonicTime::encode const): Deleted. (WTF::MonotonicTime::decode): Deleted. * wtf/NaturalLoops.h: * wtf/NoLock.h: * wtf/OSAllocator.h: * wtf/OptionSet.h: * wtf/Optional.h: * wtf/OrderMaker.h: * wtf/Packed.h: (WTF::alignof): * wtf/PackedIntVector.h: (WTF::PackedIntVector::PackedIntVector): Deleted. (WTF::PackedIntVector::operator=): Deleted. (WTF::PackedIntVector::size const): Deleted. (WTF::PackedIntVector::ensureSize): Deleted. (WTF::PackedIntVector::resize): Deleted. (WTF::PackedIntVector::clearAll): Deleted. (WTF::PackedIntVector::get const): Deleted. (WTF::PackedIntVector::set): Deleted. (WTF::PackedIntVector::mask): Deleted. * wtf/PageBlock.h: * wtf/ParallelJobsOpenMP.h: * wtf/ParkingLot.h: * wtf/PriorityQueue.h: (WTF::PriorityQueue::size const): Deleted. (WTF::PriorityQueue::isEmpty const): Deleted. (WTF::PriorityQueue::enqueue): Deleted. (WTF::PriorityQueue::peek const): Deleted. (WTF::PriorityQueue::dequeue): Deleted. (WTF::PriorityQueue::decreaseKey): Deleted. (WTF::PriorityQueue::increaseKey): Deleted. (WTF::PriorityQueue::begin const): Deleted. (WTF::PriorityQueue::end const): Deleted. (WTF::PriorityQueue::isValidHeap const): Deleted. (WTF::PriorityQueue::parentOf): Deleted. (WTF::PriorityQueue::leftChildOf): Deleted. (WTF::PriorityQueue::rightChildOf): Deleted. (WTF::PriorityQueue::siftUp): Deleted. (WTF::PriorityQueue::siftDown): Deleted. * wtf/RandomDevice.h: * wtf/Range.h: * wtf/RangeSet.h: (WTF::RangeSet::RangeSet): Deleted. (WTF::RangeSet::~RangeSet): Deleted. (WTF::RangeSet::add): Deleted. (WTF::RangeSet::contains const): Deleted. (WTF::RangeSet::overlaps const): Deleted. (WTF::RangeSet::clear): Deleted. (WTF::RangeSet::dump const): Deleted. (WTF::RangeSet::dumpRaw const): Deleted. (WTF::RangeSet::begin const): Deleted. (WTF::RangeSet::end const): Deleted. (WTF::RangeSet::addAll): Deleted. (WTF::RangeSet::compact): Deleted. (WTF::RangeSet::overlapsNonEmpty): Deleted. (WTF::RangeSet::subsumesNonEmpty): Deleted. (WTF::RangeSet::findRange const): Deleted. * wtf/RecursableLambda.h: * wtf/RedBlackTree.h: (WTF::RedBlackTree::Node::successor const): Deleted. (WTF::RedBlackTree::Node::predecessor const): Deleted. (WTF::RedBlackTree::Node::successor): Deleted. (WTF::RedBlackTree::Node::predecessor): Deleted. (WTF::RedBlackTree::Node::reset): Deleted. (WTF::RedBlackTree::Node::parent const): Deleted. (WTF::RedBlackTree::Node::setParent): Deleted. (WTF::RedBlackTree::Node::left const): Deleted. (WTF::RedBlackTree::Node::setLeft): Deleted. (WTF::RedBlackTree::Node::right const): Deleted. (WTF::RedBlackTree::Node::setRight): Deleted. (WTF::RedBlackTree::Node::color const): Deleted. (WTF::RedBlackTree::Node::setColor): Deleted. (WTF::RedBlackTree::RedBlackTree): Deleted. (WTF::RedBlackTree::insert): Deleted. (WTF::RedBlackTree::remove): Deleted. (WTF::RedBlackTree::findExact const): Deleted. (WTF::RedBlackTree::findLeastGreaterThanOrEqual const): Deleted. (WTF::RedBlackTree::findGreatestLessThanOrEqual const): Deleted. (WTF::RedBlackTree::first const): Deleted. (WTF::RedBlackTree::last const): Deleted. (WTF::RedBlackTree::size): Deleted. (WTF::RedBlackTree::isEmpty): Deleted. (WTF::RedBlackTree::treeMinimum): Deleted. (WTF::RedBlackTree::treeMaximum): Deleted. (WTF::RedBlackTree::treeInsert): Deleted. (WTF::RedBlackTree::leftRotate): Deleted. (WTF::RedBlackTree::rightRotate): Deleted. (WTF::RedBlackTree::removeFixup): Deleted. * wtf/ResourceUsage.h: * wtf/RunLoop.cpp: * wtf/RunLoopTimer.h: * wtf/SHA1.h: * wtf/Seconds.h: (WTF::Seconds::Seconds): Deleted. (WTF::Seconds::value const): Deleted. (WTF::Seconds::minutes const): Deleted. (WTF::Seconds::seconds const): Deleted. (WTF::Seconds::milliseconds const): Deleted. (WTF::Seconds::microseconds const): Deleted. (WTF::Seconds::nanoseconds const): Deleted. (WTF::Seconds::minutesAs const): Deleted. (WTF::Seconds::secondsAs const): Deleted. (WTF::Seconds::millisecondsAs const): Deleted. (WTF::Seconds::microsecondsAs const): Deleted. (WTF::Seconds::nanosecondsAs const): Deleted. (WTF::Seconds::fromMinutes): Deleted. (WTF::Seconds::fromHours): Deleted. (WTF::Seconds::fromMilliseconds): Deleted. (WTF::Seconds::fromMicroseconds): Deleted. (WTF::Seconds::fromNanoseconds): Deleted. (WTF::Seconds::infinity): Deleted. (WTF::Seconds::nan): Deleted. (WTF::Seconds::operator bool const): Deleted. (WTF::Seconds::operator+ const): Deleted. (WTF::Seconds::operator- const): Deleted. (WTF::Seconds::operator* const): Deleted. (WTF::Seconds::operator/ const): Deleted. (WTF::Seconds::operator% const): Deleted. (WTF::Seconds::operator+=): Deleted. (WTF::Seconds::operator-=): Deleted. (WTF::Seconds::operator*=): Deleted. (WTF::Seconds::operator/=): Deleted. (WTF::Seconds::operator%=): Deleted. (WTF::Seconds::operator== const): Deleted. (WTF::Seconds::operator!= const): Deleted. (WTF::Seconds::operator< const): Deleted. (WTF::Seconds::operator> const): Deleted. (WTF::Seconds::operator<= const): Deleted. (WTF::Seconds::operator>= const): Deleted. (WTF::Seconds::isolatedCopy const): Deleted. (WTF::Seconds::encode const): Deleted. (WTF::Seconds::decode): Deleted. * wtf/SegmentedVector.h: (WTF::SegmentedVector::~SegmentedVector): Deleted. (WTF::SegmentedVector::size const): Deleted. (WTF::SegmentedVector::isEmpty const): Deleted. (WTF::SegmentedVector::at): Deleted. (WTF::SegmentedVector::at const): Deleted. (WTF::SegmentedVector::operator[]): Deleted. (WTF::SegmentedVector::operator[] const): Deleted. (WTF::SegmentedVector::first): Deleted. (WTF::SegmentedVector::first const): Deleted. (WTF::SegmentedVector::last): Deleted. (WTF::SegmentedVector::last const): Deleted. (WTF::SegmentedVector::takeLast): Deleted. (WTF::SegmentedVector::append): Deleted. (WTF::SegmentedVector::alloc): Deleted. (WTF::SegmentedVector::removeLast): Deleted. (WTF::SegmentedVector::grow): Deleted. (WTF::SegmentedVector::clear): Deleted. (WTF::SegmentedVector::begin): Deleted. (WTF::SegmentedVector::end): Deleted. (WTF::SegmentedVector::shrinkToFit): Deleted. (WTF::SegmentedVector::deleteAllSegments): Deleted. (WTF::SegmentedVector::segmentExistsFor): Deleted. (WTF::SegmentedVector::segmentFor): Deleted. (WTF::SegmentedVector::subscriptFor): Deleted. (WTF::SegmentedVector::ensureSegmentsFor): Deleted. (WTF::SegmentedVector::ensureSegment): Deleted. (WTF::SegmentedVector::allocateSegment): Deleted. * wtf/SetForScope.h: * wtf/SingleRootGraph.h: * wtf/SinglyLinkedList.h: * wtf/SmallPtrSet.h: * wtf/SpanningTree.h: * wtf/Spectrum.h: * wtf/StackBounds.h: * wtf/StackShot.h: * wtf/StackShotProfiler.h: * wtf/StackStats.h: * wtf/StackTrace.h: * wtf/StreamBuffer.h: * wtf/SynchronizedFixedQueue.h: (WTF::SynchronizedFixedQueue::create): Deleted. (WTF::SynchronizedFixedQueue::open): Deleted. (WTF::SynchronizedFixedQueue::close): Deleted. (WTF::SynchronizedFixedQueue::isOpen): Deleted. (WTF::SynchronizedFixedQueue::enqueue): Deleted. (WTF::SynchronizedFixedQueue::dequeue): Deleted. (WTF::SynchronizedFixedQueue::SynchronizedFixedQueue): Deleted. * wtf/SystemTracing.h: * wtf/ThreadGroup.h: (WTF::ThreadGroup::create): Deleted. (WTF::ThreadGroup::threads const): Deleted. (WTF::ThreadGroup::getLock): Deleted. (WTF::ThreadGroup::weakFromThis): Deleted. * wtf/ThreadSpecific.h: * wtf/ThreadingPrimitives.h: (WTF::Mutex::impl): Deleted. * wtf/TimeWithDynamicClockType.h: (WTF::TimeWithDynamicClockType::TimeWithDynamicClockType): Deleted. (WTF::TimeWithDynamicClockType::fromRawSeconds): Deleted. (WTF::TimeWithDynamicClockType::secondsSinceEpoch const): Deleted. (WTF::TimeWithDynamicClockType::clockType const): Deleted. (WTF::TimeWithDynamicClockType::withSameClockAndRawSeconds const): Deleted. (WTF::TimeWithDynamicClockType::operator bool const): Deleted. (WTF::TimeWithDynamicClockType::operator+ const): Deleted. (WTF::TimeWithDynamicClockType::operator- const): Deleted. (WTF::TimeWithDynamicClockType::operator+=): Deleted. (WTF::TimeWithDynamicClockType::operator-=): Deleted. (WTF::TimeWithDynamicClockType::operator== const): Deleted. (WTF::TimeWithDynamicClockType::operator!= const): Deleted. * wtf/TimingScope.h: * wtf/TinyLRUCache.h: * wtf/TinyPtrSet.h: * wtf/URLParser.cpp: * wtf/URLParser.h: * wtf/Unexpected.h: * wtf/Variant.h: * wtf/WTFSemaphore.h: (WTF::Semaphore::Semaphore): Deleted. (WTF::Semaphore::signal): Deleted. (WTF::Semaphore::waitUntil): Deleted. (WTF::Semaphore::waitFor): Deleted. (WTF::Semaphore::wait): Deleted. * wtf/WallTime.h: (WTF::WallTime::WallTime): Deleted. (WTF::WallTime::fromRawSeconds): Deleted. (WTF::WallTime::infinity): Deleted. (WTF::WallTime::nan): Deleted. (WTF::WallTime::secondsSinceEpoch const): Deleted. (WTF::WallTime::approximateWallTime const): Deleted. (WTF::WallTime::operator bool const): Deleted. (WTF::WallTime::operator+ const): Deleted. (WTF::WallTime::operator- const): Deleted. (WTF::WallTime::operator+=): Deleted. (WTF::WallTime::operator-=): Deleted. (WTF::WallTime::operator== const): Deleted. (WTF::WallTime::operator!= const): Deleted. (WTF::WallTime::operator< const): Deleted. (WTF::WallTime::operator> const): Deleted. (WTF::WallTime::operator<= const): Deleted. (WTF::WallTime::operator>= const): Deleted. (WTF::WallTime::isolatedCopy const): Deleted. * wtf/WeakHashSet.h: (WTF::WeakHashSet::WeakHashSetConstIterator::WeakHashSetConstIterator): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::get const): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::operator* const): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::operator-> const): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::operator++): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::skipEmptyBuckets): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::operator== const): Deleted. (WTF::WeakHashSet::WeakHashSetConstIterator::operator!= const): Deleted. (WTF::WeakHashSet::WeakHashSet): Deleted. (WTF::WeakHashSet::begin const): Deleted. (WTF::WeakHashSet::end const): Deleted. (WTF::WeakHashSet::add): Deleted. (WTF::WeakHashSet::remove): Deleted. (WTF::WeakHashSet::contains const): Deleted. (WTF::WeakHashSet::capacity const): Deleted. (WTF::WeakHashSet::computesEmpty const): Deleted. (WTF::WeakHashSet::hasNullReferences const): Deleted. (WTF::WeakHashSet::computeSize const): Deleted. (WTF::WeakHashSet::checkConsistency const): Deleted. * wtf/WeakRandom.h: (WTF::WeakRandom::WeakRandom): Deleted. (WTF::WeakRandom::setSeed): Deleted. (WTF::WeakRandom::seed const): Deleted. (WTF::WeakRandom::get): Deleted. (WTF::WeakRandom::getUint32): Deleted. (WTF::WeakRandom::lowOffset): Deleted. (WTF::WeakRandom::highOffset): Deleted. (WTF::WeakRandom::nextState): Deleted. (WTF::WeakRandom::generate): Deleted. (WTF::WeakRandom::advance): Deleted. * wtf/WordLock.h: (WTF::WordLock::lock): Deleted. (WTF::WordLock::unlock): Deleted. (WTF::WordLock::isHeld const): Deleted. (WTF::WordLock::isLocked const): Deleted. (WTF::WordLock::isFullyReset const): Deleted. * wtf/generic/MainThreadGeneric.cpp: * wtf/glib/GMutexLocker.h: * wtf/linux/CurrentProcessMemoryStatus.h: * wtf/posix/ThreadingPOSIX.cpp: (WTF::Semaphore::Semaphore): Deleted. (WTF::Semaphore::~Semaphore): Deleted. (WTF::Semaphore::wait): Deleted. (WTF::Semaphore::post): Deleted. * wtf/text/ASCIILiteral.h: (WTF::ASCIILiteral::operator const char* const): Deleted. (WTF::ASCIILiteral::fromLiteralUnsafe): Deleted. (WTF::ASCIILiteral::null): Deleted. (WTF::ASCIILiteral::characters const): Deleted. (WTF::ASCIILiteral::ASCIILiteral): Deleted. * wtf/text/AtomString.h: (WTF::AtomString::operator=): Deleted. (WTF::AtomString::isHashTableDeletedValue const): Deleted. (WTF::AtomString::existingHash const): Deleted. (WTF::AtomString::operator const String& const): Deleted. (WTF::AtomString::string const): Deleted. (WTF::AtomString::impl const): Deleted. (WTF::AtomString::is8Bit const): Deleted. (WTF::AtomString::characters8 const): Deleted. (WTF::AtomString::characters16 const): Deleted. (WTF::AtomString::length const): Deleted. (WTF::AtomString::operator[] const): Deleted. (WTF::AtomString::contains const): Deleted. (WTF::AtomString::containsIgnoringASCIICase const): Deleted. (WTF::AtomString::find const): Deleted. (WTF::AtomString::findIgnoringASCIICase const): Deleted. (WTF::AtomString::startsWith const): Deleted. (WTF::AtomString::startsWithIgnoringASCIICase const): Deleted. (WTF::AtomString::endsWith const): Deleted. (WTF::AtomString::endsWithIgnoringASCIICase const): Deleted. (WTF::AtomString::toInt const): Deleted. (WTF::AtomString::toDouble const): Deleted. (WTF::AtomString::toFloat const): Deleted. (WTF::AtomString::percentage const): Deleted. (WTF::AtomString::isNull const): Deleted. (WTF::AtomString::isEmpty const): Deleted. (WTF::AtomString::operator NSString * const): Deleted. * wtf/text/AtomStringImpl.h: (WTF::AtomStringImpl::lookUp): Deleted. (WTF::AtomStringImpl::add): Deleted. (WTF::AtomStringImpl::addWithStringTableProvider): Deleted. * wtf/text/CString.h: (WTF::CStringBuffer::data): Deleted. (WTF::CStringBuffer::length const): Deleted. (WTF::CStringBuffer::CStringBuffer): Deleted. (WTF::CStringBuffer::mutableData): Deleted. (WTF::CString::CString): Deleted. (WTF::CString::data const): Deleted. (WTF::CString::length const): Deleted. (WTF::CString::isNull const): Deleted. (WTF::CString::buffer const): Deleted. (WTF::CString::isHashTableDeletedValue const): Deleted. * wtf/text/ExternalStringImpl.h: (WTF::ExternalStringImpl::freeExternalBuffer): Deleted. * wtf/text/LineBreakIteratorPoolICU.h: * wtf/text/NullTextBreakIterator.h: * wtf/text/OrdinalNumber.h: * wtf/text/StringBuffer.h: * wtf/text/StringBuilder.h: * wtf/text/StringConcatenateNumbers.h: * wtf/text/StringHasher.h: * wtf/text/StringImpl.h: * wtf/text/StringView.cpp: * wtf/text/StringView.h: (WTF::StringView::left const): Deleted. (WTF::StringView::right const): Deleted. (WTF::StringView::underlyingStringIsValid const): Deleted. (WTF::StringView::setUnderlyingString): Deleted. * wtf/text/SymbolImpl.h: (WTF::SymbolImpl::StaticSymbolImpl::StaticSymbolImpl): Deleted. (WTF::SymbolImpl::StaticSymbolImpl::operator SymbolImpl&): Deleted. (WTF::PrivateSymbolImpl::PrivateSymbolImpl): Deleted. (WTF::RegisteredSymbolImpl::symbolRegistry const): Deleted. (WTF::RegisteredSymbolImpl::clearSymbolRegistry): Deleted. (WTF::RegisteredSymbolImpl::RegisteredSymbolImpl): Deleted. * wtf/text/SymbolRegistry.h: * wtf/text/TextBreakIterator.h: * wtf/text/TextPosition.h: * wtf/text/TextStream.h: * wtf/text/WTFString.h: (WTF::String::swap): Deleted. (WTF::String::adopt): Deleted. (WTF::String::isNull const): Deleted. (WTF::String::isEmpty const): Deleted. (WTF::String::impl const): Deleted. (WTF::String::releaseImpl): Deleted. (WTF::String::length const): Deleted. (WTF::String::characters8 const): Deleted. (WTF::String::characters16 const): Deleted. (WTF::String::is8Bit const): Deleted. (WTF::String::sizeInBytes const): Deleted. (WTF::String::operator[] const): Deleted. (WTF::String::find const): Deleted. (WTF::String::findIgnoringASCIICase const): Deleted. (WTF::String::reverseFind const): Deleted. (WTF::String::contains const): Deleted. (WTF::String::containsIgnoringASCIICase const): Deleted. (WTF::String::startsWith const): Deleted. (WTF::String::startsWithIgnoringASCIICase const): Deleted. (WTF::String::hasInfixStartingAt const): Deleted. (WTF::String::endsWith const): Deleted. (WTF::String::endsWithIgnoringASCIICase const): Deleted. (WTF::String::hasInfixEndingAt const): Deleted. (WTF::String::append): Deleted. (WTF::String::left const): Deleted. (WTF::String::right const): Deleted. (WTF::String::createUninitialized): Deleted. (WTF::String::fromUTF8WithLatin1Fallback): Deleted. (WTF::String::isAllASCII const): Deleted. (WTF::String::isAllLatin1 const): Deleted. (WTF::String::isSpecialCharacter const): Deleted. (WTF::String::isHashTableDeletedValue const): Deleted. (WTF::String::hash const): Deleted. (WTF::String::existingHash const): Deleted. * wtf/text/cf/TextBreakIteratorCF.h: * wtf/text/icu/TextBreakIteratorICU.h: * wtf/text/icu/UTextProviderLatin1.h: * wtf/threads/BinarySemaphore.h: (WTF::BinarySemaphore::waitFor): Deleted. (WTF::BinarySemaphore::wait): Deleted. * wtf/unicode/Collator.h: * wtf/win/GDIObject.h: * wtf/win/PathWalker.h: * wtf/win/Win32Handle.h: Canonical link: https://commits.webkit.org/214396@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248546 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-08-12 20:57:15 +00:00
WTF_MAKE_STRUCT_FAST_ALLOCATED;
Further simplify StringBuilder usage by standardizing hex formating to a single hex() function https://bugs.webkit.org/show_bug.cgi?id=205759 Reviewed by Dean Jackson. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): * runtime/JSGlobalObjectFunctions.cpp: (JSC::encode): (JSC::globalFuncEscape): Replace appendUnsignedAsHex() and appendByteAsHex() with append(hex()). Source/WebCore: * Modules/websockets/WebSocket.cpp: (WebCore::encodeProtocolString): * css/CSSMarkup.cpp: (WebCore::serializeCharacterAsCodePoint): * css/parser/CSSParserToken.cpp: (WebCore::CSSParserToken::serialize const): * platform/graphics/Color.cpp: (WebCore::Color::serialized const): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::processMpegTsSection): * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: (WebCore::generateHashedName): * platform/network/curl/CurlCacheEntry.cpp: (WebCore::CurlCacheEntry::generateBaseFilename): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Replace appendByteAsHex()/appendUnsignedAsHex()/appendUnsignedAsHexFixedSize() with append(hex()). * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::appendFormURLEncoded): This was the last non-StringBuilder/makeString use of appendByteAsHex. Rather than keep appendByteAsHex around, it is replaced with direct appends of the character buffer hex() produces. Source/WebKit: * UIProcess/DeviceIdHashSaltStorage.cpp: (WebKit::DeviceIdHashSaltStorage::completeDeviceIdHashSaltForOriginCall): * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Replace appendUnsignedAsHex() with append(hex()). Source/WTF: Removes appendByteAsHex, appendUnsignedAsHex and appendUnsignedAsHexFixedSize with the following mappings: appendByteAsHex(value, builder, case) -> builder.append(hex(static_cast<unsigned char>(value), 2, case)) appendUnsignedAsHex(value, builder, case) -> builder.append(hex(value, case)) appendUnsignedAsHexFixedSize(value, builder, size, case) -> builder.append(hex(value, size, case)) Adds new API test for HexNumber.cpp * wtf/HexNumber.h: (WTF::appendByteAsHex): Deleted. (WTF::appendUnsignedAsHex): Deleted. (WTF::appendUnsignedAsHexFixedSize): Deleted. Remove now unused helper functions. * wtf/FileSystem.cpp: (WTF::FileSystemImpl::encodeForFileName): Replace appendByteAsHex with direct use of hex(x, 2). The static_cast is needed since there was an implicit down cast when appendByteAsHex was used. * wtf/Logger.cpp: (WTF::Logger::LogSiteIdentifier::toString const): (WTF::>::toString): * wtf/UUID.cpp: (WTF::createCanonicalUUIDString): Replace appendUnsignedAsHex/appendUnsignedAsHexFixedSize with hex(). Use makeString() rather StringBuilder to simplify things further. * wtf/text/WTFString.cpp: (asciiDebug): Replace appendUnsignedAsHexFixedSize with append(hex()). Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/HexNumber.cpp: Added. Add testing for hex formatting of integers. Canonical link: https://commits.webkit.org/218921@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254046 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 00:20:57 +00:00
std::array<LChar, 16> buffer;
Continue reducing use of String::format, now focusing on hex: "%p", "%x", etc. https://bugs.webkit.org/show_bug.cgi?id=194752 Reviewed by Daniel Bates. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): Added back the "0x" that was removed when changing this file to use appendUnsignedAsHex instead of "%p". The intent at that time was to keep behavior the same, so let's do that. * parser/Lexer.cpp: (JSC::Lexer<T>::invalidCharacterMessage const): Use makeString and hex instead of String::format and "%04x". Source/WebCore: * Modules/websockets/WebSocket.cpp: Added an include of HexNumber.h. This previously got included because of Logger.h, but that no longer pulls in HexNumber.h. * css/CSSMarkup.cpp: Removed unneeded include of StringBuffer.h. * css/CSSPrimitiveValue.cpp: Ditto. * css/CSSUnicodeRangeValue.cpp: (WebCore::CSSUnicodeRangeValue::customCSSText const): Use makeString and hex instead of String::format and "%x". * html/HTMLMediaElement.h: (WTF::ValueToString<WebCore::TextTrackCue::string): Use a non-template function, TextTrackCure::debugString, so we don't need to use HextNumber.h in a header. * html/canvas/WebGLRenderingContextBase.cpp: (GetErrorString): Use makeString and hex instead of String::format and "%04x". * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::debugString const): Added. Moved string conversion here from HTMLMediaElement.h and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * html/track/TextTrackCue.h: Added TextTrackCue::debugString. * page/linux/ResourceUsageOverlayLinux.cpp: (WebCore::formatByteNumber): Use makeString and FormattedNumber::fixedWidth instead of String::format and "%.1f" etc. * platform/cocoa/KeyEventCocoa.mm: (WebCore::keyIdentifierForCharCode): Use the new hex function here instead of the old code that did each of the four characters explicitly. * platform/gamepad/mac/HIDGamepad.cpp: (WebCore::HIDGamepad::HIDGamepad): Use makeString instead of String::format. * platform/graphics/Color.cpp: (WebCore::Color::nameForRenderTreeAsText const): Use hex instead of doing each digit separately. * platform/graphics/FloatPolygon.cpp: (WebCore::FloatPolygonEdge::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * platform/graphics/FloatPolygon.h: Updated for the above. * platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::GraphicsLayerCA::setName): Use makeString instead of String::format. (WebCore::GraphicsLayerCA::recursiveCommitChanges): DItto. * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::load): Ditto. (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Ditto. * platform/gtk/PlatformKeyboardEventGtk.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForGdkKeyCode): Ditto. * platform/libwpe/PlatformKeyboardEventLibWPE.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForWPEKeyCode): Ditto. * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: (WebCore::GStreamerVideoEncoder::makeElement): Ditto. (WebCore::GStreamerVideoEncoder::InitEncode): Ditto. * platform/text/TextCodecLatin1.cpp: Removed unneeded include of StringBuffer.h and "using namespace WTF". * platform/win/GDIObjectCounter.cpp: (WebCore::GDIObjectCounter::GDIObjectCounter): Use makeString instead of String::format. * platform/win/KeyEventWin.cpp: (WebCore::keyIdentifierForWindowsKeyCode): Ditto. * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/FloatingObjects.h: Updated for the above. * rendering/RenderFragmentContainer.cpp: (WebCore::RenderFragmentContainer::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/RenderFragmentContainer.h: Updated for the above. * rendering/RenderFragmentedFlow.h: Ditto. * testing/Internals.cpp: (WebCore::Internals::address): Use makeString instead of String::format. Source/WebCore/PAL: * pal/FileSizeFormatter.cpp: (fileSizeDescription): Use makeString instead of String::format. Source/WebKit: * Platform/IPC/win/ConnectionWin.cpp: (IPC::Connection::createServerAndClientIdentifiers): Use makeString instead of String::format. * Shared/win/WebEventFactory.cpp: (WebKit::keyIdentifierFromEvent): Ditto. * UIProcess/API/APINavigation.cpp: (API::Navigation::loggingString const): Use hex instead of String::format. * UIProcess/SuspendedPageProxy.cpp: (WebKit::SuspendedPageProxy::loggingString const): Ditto. * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Added a "0x". * UIProcess/gtk/InputMethodFilter.cpp: (WebKit::InputMethodFilter::logHandleKeyboardEventForTesting): Use makeString and hex instead of String::format and "%x". (WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting): Ditto. Source/WTF: * WTF.xcodeproj/project.pbxproj: Added HexNumber.cpp and Logger.cpp. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.cpp: Added. (WTF::Internal::appendHex): Non-inline, non-template hex formatting logic. * wtf/HexNumber.h: (WTF::Internal::appendHex): Refactored main logic of appendUnsignedAsHex and appendUnsignedAsHexFixedSize so they can be reused in a function named hex for use with StringTypeAdapter. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::hex): Added. (WTF::StringTypeAdapter<HexNumberBuffer>): Added. * wtf/Logger.cpp: Added. (WTF::Logger::LogSiteIdentifier::toString const): Made this a non-template function and moved it here so that we don't need to include HexNumber.h in Logger.h. Since HexNumber.h has substantial code in it, it's good if we don't include it in any other headers. * wtf/Logger.h: (WTF::LogArgument<Logger::LogSiteIdentifier>::toString): Changed to call a non-template function, LogSiteIdentifier::toString. * wtf/text/StringConcatenateNumbers.h: Replaced overloaded writeTo functions with function templates and used StringImpl::copyCharacters instead of hand-written loops. Canonical link: https://commits.webkit.org/209182@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-19 02:04:33 +00:00
unsigned length;
Further simplify StringBuilder usage by standardizing hex formating to a single hex() function https://bugs.webkit.org/show_bug.cgi?id=205759 Reviewed by Dean Jackson. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): * runtime/JSGlobalObjectFunctions.cpp: (JSC::encode): (JSC::globalFuncEscape): Replace appendUnsignedAsHex() and appendByteAsHex() with append(hex()). Source/WebCore: * Modules/websockets/WebSocket.cpp: (WebCore::encodeProtocolString): * css/CSSMarkup.cpp: (WebCore::serializeCharacterAsCodePoint): * css/parser/CSSParserToken.cpp: (WebCore::CSSParserToken::serialize const): * platform/graphics/Color.cpp: (WebCore::Color::serialized const): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::processMpegTsSection): * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: (WebCore::generateHashedName): * platform/network/curl/CurlCacheEntry.cpp: (WebCore::CurlCacheEntry::generateBaseFilename): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Replace appendByteAsHex()/appendUnsignedAsHex()/appendUnsignedAsHexFixedSize() with append(hex()). * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::appendFormURLEncoded): This was the last non-StringBuilder/makeString use of appendByteAsHex. Rather than keep appendByteAsHex around, it is replaced with direct appends of the character buffer hex() produces. Source/WebKit: * UIProcess/DeviceIdHashSaltStorage.cpp: (WebKit::DeviceIdHashSaltStorage::completeDeviceIdHashSaltForOriginCall): * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Replace appendUnsignedAsHex() with append(hex()). Source/WTF: Removes appendByteAsHex, appendUnsignedAsHex and appendUnsignedAsHexFixedSize with the following mappings: appendByteAsHex(value, builder, case) -> builder.append(hex(static_cast<unsigned char>(value), 2, case)) appendUnsignedAsHex(value, builder, case) -> builder.append(hex(value, case)) appendUnsignedAsHexFixedSize(value, builder, size, case) -> builder.append(hex(value, size, case)) Adds new API test for HexNumber.cpp * wtf/HexNumber.h: (WTF::appendByteAsHex): Deleted. (WTF::appendUnsignedAsHex): Deleted. (WTF::appendUnsignedAsHexFixedSize): Deleted. Remove now unused helper functions. * wtf/FileSystem.cpp: (WTF::FileSystemImpl::encodeForFileName): Replace appendByteAsHex with direct use of hex(x, 2). The static_cast is needed since there was an implicit down cast when appendByteAsHex was used. * wtf/Logger.cpp: (WTF::Logger::LogSiteIdentifier::toString const): (WTF::>::toString): * wtf/UUID.cpp: (WTF::createCanonicalUUIDString): Replace appendUnsignedAsHex/appendUnsignedAsHexFixedSize with hex(). Use makeString() rather StringBuilder to simplify things further. * wtf/text/WTFString.cpp: (asciiDebug): Replace appendUnsignedAsHexFixedSize with append(hex()). Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/HexNumber.cpp: Added. Add testing for hex formatting of integers. Canonical link: https://commits.webkit.org/218921@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254046 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 00:20:57 +00:00
const LChar* characters() const { return &*(buffer.end() - length); }
Continue reducing use of String::format, now focusing on hex: "%p", "%x", etc. https://bugs.webkit.org/show_bug.cgi?id=194752 Reviewed by Daniel Bates. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): Added back the "0x" that was removed when changing this file to use appendUnsignedAsHex instead of "%p". The intent at that time was to keep behavior the same, so let's do that. * parser/Lexer.cpp: (JSC::Lexer<T>::invalidCharacterMessage const): Use makeString and hex instead of String::format and "%04x". Source/WebCore: * Modules/websockets/WebSocket.cpp: Added an include of HexNumber.h. This previously got included because of Logger.h, but that no longer pulls in HexNumber.h. * css/CSSMarkup.cpp: Removed unneeded include of StringBuffer.h. * css/CSSPrimitiveValue.cpp: Ditto. * css/CSSUnicodeRangeValue.cpp: (WebCore::CSSUnicodeRangeValue::customCSSText const): Use makeString and hex instead of String::format and "%x". * html/HTMLMediaElement.h: (WTF::ValueToString<WebCore::TextTrackCue::string): Use a non-template function, TextTrackCure::debugString, so we don't need to use HextNumber.h in a header. * html/canvas/WebGLRenderingContextBase.cpp: (GetErrorString): Use makeString and hex instead of String::format and "%04x". * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::debugString const): Added. Moved string conversion here from HTMLMediaElement.h and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * html/track/TextTrackCue.h: Added TextTrackCue::debugString. * page/linux/ResourceUsageOverlayLinux.cpp: (WebCore::formatByteNumber): Use makeString and FormattedNumber::fixedWidth instead of String::format and "%.1f" etc. * platform/cocoa/KeyEventCocoa.mm: (WebCore::keyIdentifierForCharCode): Use the new hex function here instead of the old code that did each of the four characters explicitly. * platform/gamepad/mac/HIDGamepad.cpp: (WebCore::HIDGamepad::HIDGamepad): Use makeString instead of String::format. * platform/graphics/Color.cpp: (WebCore::Color::nameForRenderTreeAsText const): Use hex instead of doing each digit separately. * platform/graphics/FloatPolygon.cpp: (WebCore::FloatPolygonEdge::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * platform/graphics/FloatPolygon.h: Updated for the above. * platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::GraphicsLayerCA::setName): Use makeString instead of String::format. (WebCore::GraphicsLayerCA::recursiveCommitChanges): DItto. * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::load): Ditto. (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Ditto. * platform/gtk/PlatformKeyboardEventGtk.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForGdkKeyCode): Ditto. * platform/libwpe/PlatformKeyboardEventLibWPE.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForWPEKeyCode): Ditto. * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: (WebCore::GStreamerVideoEncoder::makeElement): Ditto. (WebCore::GStreamerVideoEncoder::InitEncode): Ditto. * platform/text/TextCodecLatin1.cpp: Removed unneeded include of StringBuffer.h and "using namespace WTF". * platform/win/GDIObjectCounter.cpp: (WebCore::GDIObjectCounter::GDIObjectCounter): Use makeString instead of String::format. * platform/win/KeyEventWin.cpp: (WebCore::keyIdentifierForWindowsKeyCode): Ditto. * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/FloatingObjects.h: Updated for the above. * rendering/RenderFragmentContainer.cpp: (WebCore::RenderFragmentContainer::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/RenderFragmentContainer.h: Updated for the above. * rendering/RenderFragmentedFlow.h: Ditto. * testing/Internals.cpp: (WebCore::Internals::address): Use makeString instead of String::format. Source/WebCore/PAL: * pal/FileSizeFormatter.cpp: (fileSizeDescription): Use makeString instead of String::format. Source/WebKit: * Platform/IPC/win/ConnectionWin.cpp: (IPC::Connection::createServerAndClientIdentifiers): Use makeString instead of String::format. * Shared/win/WebEventFactory.cpp: (WebKit::keyIdentifierFromEvent): Ditto. * UIProcess/API/APINavigation.cpp: (API::Navigation::loggingString const): Use hex instead of String::format. * UIProcess/SuspendedPageProxy.cpp: (WebKit::SuspendedPageProxy::loggingString const): Ditto. * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Added a "0x". * UIProcess/gtk/InputMethodFilter.cpp: (WebKit::InputMethodFilter::logHandleKeyboardEventForTesting): Use makeString and hex instead of String::format and "%x". (WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting): Ditto. Source/WTF: * WTF.xcodeproj/project.pbxproj: Added HexNumber.cpp and Logger.cpp. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.cpp: Added. (WTF::Internal::appendHex): Non-inline, non-template hex formatting logic. * wtf/HexNumber.h: (WTF::Internal::appendHex): Refactored main logic of appendUnsignedAsHex and appendUnsignedAsHexFixedSize so they can be reused in a function named hex for use with StringTypeAdapter. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::hex): Added. (WTF::StringTypeAdapter<HexNumberBuffer>): Added. * wtf/Logger.cpp: Added. (WTF::Logger::LogSiteIdentifier::toString const): Made this a non-template function and moved it here so that we don't need to include HexNumber.h in Logger.h. Since HexNumber.h has substantial code in it, it's good if we don't include it in any other headers. * wtf/Logger.h: (WTF::LogArgument<Logger::LogSiteIdentifier>::toString): Changed to call a non-template function, LogSiteIdentifier::toString. * wtf/text/StringConcatenateNumbers.h: Replaced overloaded writeTo functions with function templates and used StringImpl::copyCharacters instead of hand-written loops. Canonical link: https://commits.webkit.org/209182@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-19 02:04:33 +00:00
};
template<typename NumberType> HexNumberBuffer hex(NumberType number, unsigned minimumDigits = 0, HexConversionMode mode = Uppercase)
{
// Each byte can generate up to two digits.
HexNumberBuffer buffer;
Further simplify StringBuilder usage by standardizing hex formating to a single hex() function https://bugs.webkit.org/show_bug.cgi?id=205759 Reviewed by Dean Jackson. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): * runtime/JSGlobalObjectFunctions.cpp: (JSC::encode): (JSC::globalFuncEscape): Replace appendUnsignedAsHex() and appendByteAsHex() with append(hex()). Source/WebCore: * Modules/websockets/WebSocket.cpp: (WebCore::encodeProtocolString): * css/CSSMarkup.cpp: (WebCore::serializeCharacterAsCodePoint): * css/parser/CSSParserToken.cpp: (WebCore::CSSParserToken::serialize const): * platform/graphics/Color.cpp: (WebCore::Color::serialized const): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::processMpegTsSection): * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: (WebCore::generateHashedName): * platform/network/curl/CurlCacheEntry.cpp: (WebCore::CurlCacheEntry::generateBaseFilename): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Replace appendByteAsHex()/appendUnsignedAsHex()/appendUnsignedAsHexFixedSize() with append(hex()). * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::appendFormURLEncoded): This was the last non-StringBuilder/makeString use of appendByteAsHex. Rather than keep appendByteAsHex around, it is replaced with direct appends of the character buffer hex() produces. Source/WebKit: * UIProcess/DeviceIdHashSaltStorage.cpp: (WebKit::DeviceIdHashSaltStorage::completeDeviceIdHashSaltForOriginCall): * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Replace appendUnsignedAsHex() with append(hex()). Source/WTF: Removes appendByteAsHex, appendUnsignedAsHex and appendUnsignedAsHexFixedSize with the following mappings: appendByteAsHex(value, builder, case) -> builder.append(hex(static_cast<unsigned char>(value), 2, case)) appendUnsignedAsHex(value, builder, case) -> builder.append(hex(value, case)) appendUnsignedAsHexFixedSize(value, builder, size, case) -> builder.append(hex(value, size, case)) Adds new API test for HexNumber.cpp * wtf/HexNumber.h: (WTF::appendByteAsHex): Deleted. (WTF::appendUnsignedAsHex): Deleted. (WTF::appendUnsignedAsHexFixedSize): Deleted. Remove now unused helper functions. * wtf/FileSystem.cpp: (WTF::FileSystemImpl::encodeForFileName): Replace appendByteAsHex with direct use of hex(x, 2). The static_cast is needed since there was an implicit down cast when appendByteAsHex was used. * wtf/Logger.cpp: (WTF::Logger::LogSiteIdentifier::toString const): (WTF::>::toString): * wtf/UUID.cpp: (WTF::createCanonicalUUIDString): Replace appendUnsignedAsHex/appendUnsignedAsHexFixedSize with hex(). Use makeString() rather StringBuilder to simplify things further. * wtf/text/WTFString.cpp: (asciiDebug): Replace appendUnsignedAsHexFixedSize with append(hex()). Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/HexNumber.cpp: Added. Add testing for hex formatting of integers. Canonical link: https://commits.webkit.org/218921@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254046 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 00:20:57 +00:00
static_assert(sizeof(buffer.buffer) >= sizeof(NumberType) * 2, "number too large for hexNumber");
auto result = Internal::appendHex(buffer.buffer, number, minimumDigits, mode);
Continue reducing use of String::format, now focusing on hex: "%p", "%x", etc. https://bugs.webkit.org/show_bug.cgi?id=194752 Reviewed by Daniel Bates. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): Added back the "0x" that was removed when changing this file to use appendUnsignedAsHex instead of "%p". The intent at that time was to keep behavior the same, so let's do that. * parser/Lexer.cpp: (JSC::Lexer<T>::invalidCharacterMessage const): Use makeString and hex instead of String::format and "%04x". Source/WebCore: * Modules/websockets/WebSocket.cpp: Added an include of HexNumber.h. This previously got included because of Logger.h, but that no longer pulls in HexNumber.h. * css/CSSMarkup.cpp: Removed unneeded include of StringBuffer.h. * css/CSSPrimitiveValue.cpp: Ditto. * css/CSSUnicodeRangeValue.cpp: (WebCore::CSSUnicodeRangeValue::customCSSText const): Use makeString and hex instead of String::format and "%x". * html/HTMLMediaElement.h: (WTF::ValueToString<WebCore::TextTrackCue::string): Use a non-template function, TextTrackCure::debugString, so we don't need to use HextNumber.h in a header. * html/canvas/WebGLRenderingContextBase.cpp: (GetErrorString): Use makeString and hex instead of String::format and "%04x". * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::debugString const): Added. Moved string conversion here from HTMLMediaElement.h and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * html/track/TextTrackCue.h: Added TextTrackCue::debugString. * page/linux/ResourceUsageOverlayLinux.cpp: (WebCore::formatByteNumber): Use makeString and FormattedNumber::fixedWidth instead of String::format and "%.1f" etc. * platform/cocoa/KeyEventCocoa.mm: (WebCore::keyIdentifierForCharCode): Use the new hex function here instead of the old code that did each of the four characters explicitly. * platform/gamepad/mac/HIDGamepad.cpp: (WebCore::HIDGamepad::HIDGamepad): Use makeString instead of String::format. * platform/graphics/Color.cpp: (WebCore::Color::nameForRenderTreeAsText const): Use hex instead of doing each digit separately. * platform/graphics/FloatPolygon.cpp: (WebCore::FloatPolygonEdge::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * platform/graphics/FloatPolygon.h: Updated for the above. * platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::GraphicsLayerCA::setName): Use makeString instead of String::format. (WebCore::GraphicsLayerCA::recursiveCommitChanges): DItto. * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::load): Ditto. (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Ditto. * platform/gtk/PlatformKeyboardEventGtk.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForGdkKeyCode): Ditto. * platform/libwpe/PlatformKeyboardEventLibWPE.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForWPEKeyCode): Ditto. * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: (WebCore::GStreamerVideoEncoder::makeElement): Ditto. (WebCore::GStreamerVideoEncoder::InitEncode): Ditto. * platform/text/TextCodecLatin1.cpp: Removed unneeded include of StringBuffer.h and "using namespace WTF". * platform/win/GDIObjectCounter.cpp: (WebCore::GDIObjectCounter::GDIObjectCounter): Use makeString instead of String::format. * platform/win/KeyEventWin.cpp: (WebCore::keyIdentifierForWindowsKeyCode): Ditto. * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/FloatingObjects.h: Updated for the above. * rendering/RenderFragmentContainer.cpp: (WebCore::RenderFragmentContainer::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/RenderFragmentContainer.h: Updated for the above. * rendering/RenderFragmentedFlow.h: Ditto. * testing/Internals.cpp: (WebCore::Internals::address): Use makeString instead of String::format. Source/WebCore/PAL: * pal/FileSizeFormatter.cpp: (fileSizeDescription): Use makeString instead of String::format. Source/WebKit: * Platform/IPC/win/ConnectionWin.cpp: (IPC::Connection::createServerAndClientIdentifiers): Use makeString instead of String::format. * Shared/win/WebEventFactory.cpp: (WebKit::keyIdentifierFromEvent): Ditto. * UIProcess/API/APINavigation.cpp: (API::Navigation::loggingString const): Use hex instead of String::format. * UIProcess/SuspendedPageProxy.cpp: (WebKit::SuspendedPageProxy::loggingString const): Ditto. * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Added a "0x". * UIProcess/gtk/InputMethodFilter.cpp: (WebKit::InputMethodFilter::logHandleKeyboardEventForTesting): Use makeString and hex instead of String::format and "%x". (WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting): Ditto. Source/WTF: * WTF.xcodeproj/project.pbxproj: Added HexNumber.cpp and Logger.cpp. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.cpp: Added. (WTF::Internal::appendHex): Non-inline, non-template hex formatting logic. * wtf/HexNumber.h: (WTF::Internal::appendHex): Refactored main logic of appendUnsignedAsHex and appendUnsignedAsHexFixedSize so they can be reused in a function named hex for use with StringTypeAdapter. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::hex): Added. (WTF::StringTypeAdapter<HexNumberBuffer>): Added. * wtf/Logger.cpp: Added. (WTF::Logger::LogSiteIdentifier::toString const): Made this a non-template function and moved it here so that we don't need to include HexNumber.h in Logger.h. Since HexNumber.h has substantial code in it, it's good if we don't include it in any other headers. * wtf/Logger.h: (WTF::LogArgument<Logger::LogSiteIdentifier>::toString): Changed to call a non-template function, LogSiteIdentifier::toString. * wtf/text/StringConcatenateNumbers.h: Replaced overloaded writeTo functions with function templates and used StringImpl::copyCharacters instead of hand-written loops. Canonical link: https://commits.webkit.org/209182@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-19 02:04:33 +00:00
buffer.length = result.second;
return buffer;
}
template<typename NumberType> HexNumberBuffer hex(NumberType number, HexConversionMode mode)
2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
{
Continue reducing use of String::format, now focusing on hex: "%p", "%x", etc. https://bugs.webkit.org/show_bug.cgi?id=194752 Reviewed by Daniel Bates. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): Added back the "0x" that was removed when changing this file to use appendUnsignedAsHex instead of "%p". The intent at that time was to keep behavior the same, so let's do that. * parser/Lexer.cpp: (JSC::Lexer<T>::invalidCharacterMessage const): Use makeString and hex instead of String::format and "%04x". Source/WebCore: * Modules/websockets/WebSocket.cpp: Added an include of HexNumber.h. This previously got included because of Logger.h, but that no longer pulls in HexNumber.h. * css/CSSMarkup.cpp: Removed unneeded include of StringBuffer.h. * css/CSSPrimitiveValue.cpp: Ditto. * css/CSSUnicodeRangeValue.cpp: (WebCore::CSSUnicodeRangeValue::customCSSText const): Use makeString and hex instead of String::format and "%x". * html/HTMLMediaElement.h: (WTF::ValueToString<WebCore::TextTrackCue::string): Use a non-template function, TextTrackCure::debugString, so we don't need to use HextNumber.h in a header. * html/canvas/WebGLRenderingContextBase.cpp: (GetErrorString): Use makeString and hex instead of String::format and "%04x". * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::debugString const): Added. Moved string conversion here from HTMLMediaElement.h and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * html/track/TextTrackCue.h: Added TextTrackCue::debugString. * page/linux/ResourceUsageOverlayLinux.cpp: (WebCore::formatByteNumber): Use makeString and FormattedNumber::fixedWidth instead of String::format and "%.1f" etc. * platform/cocoa/KeyEventCocoa.mm: (WebCore::keyIdentifierForCharCode): Use the new hex function here instead of the old code that did each of the four characters explicitly. * platform/gamepad/mac/HIDGamepad.cpp: (WebCore::HIDGamepad::HIDGamepad): Use makeString instead of String::format. * platform/graphics/Color.cpp: (WebCore::Color::nameForRenderTreeAsText const): Use hex instead of doing each digit separately. * platform/graphics/FloatPolygon.cpp: (WebCore::FloatPolygonEdge::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * platform/graphics/FloatPolygon.h: Updated for the above. * platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::GraphicsLayerCA::setName): Use makeString instead of String::format. (WebCore::GraphicsLayerCA::recursiveCommitChanges): DItto. * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::load): Ditto. (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Ditto. * platform/gtk/PlatformKeyboardEventGtk.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForGdkKeyCode): Ditto. * platform/libwpe/PlatformKeyboardEventLibWPE.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForWPEKeyCode): Ditto. * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: (WebCore::GStreamerVideoEncoder::makeElement): Ditto. (WebCore::GStreamerVideoEncoder::InitEncode): Ditto. * platform/text/TextCodecLatin1.cpp: Removed unneeded include of StringBuffer.h and "using namespace WTF". * platform/win/GDIObjectCounter.cpp: (WebCore::GDIObjectCounter::GDIObjectCounter): Use makeString instead of String::format. * platform/win/KeyEventWin.cpp: (WebCore::keyIdentifierForWindowsKeyCode): Ditto. * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/FloatingObjects.h: Updated for the above. * rendering/RenderFragmentContainer.cpp: (WebCore::RenderFragmentContainer::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/RenderFragmentContainer.h: Updated for the above. * rendering/RenderFragmentedFlow.h: Ditto. * testing/Internals.cpp: (WebCore::Internals::address): Use makeString instead of String::format. Source/WebCore/PAL: * pal/FileSizeFormatter.cpp: (fileSizeDescription): Use makeString instead of String::format. Source/WebKit: * Platform/IPC/win/ConnectionWin.cpp: (IPC::Connection::createServerAndClientIdentifiers): Use makeString instead of String::format. * Shared/win/WebEventFactory.cpp: (WebKit::keyIdentifierFromEvent): Ditto. * UIProcess/API/APINavigation.cpp: (API::Navigation::loggingString const): Use hex instead of String::format. * UIProcess/SuspendedPageProxy.cpp: (WebKit::SuspendedPageProxy::loggingString const): Ditto. * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Added a "0x". * UIProcess/gtk/InputMethodFilter.cpp: (WebKit::InputMethodFilter::logHandleKeyboardEventForTesting): Use makeString and hex instead of String::format and "%x". (WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting): Ditto. Source/WTF: * WTF.xcodeproj/project.pbxproj: Added HexNumber.cpp and Logger.cpp. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.cpp: Added. (WTF::Internal::appendHex): Non-inline, non-template hex formatting logic. * wtf/HexNumber.h: (WTF::Internal::appendHex): Refactored main logic of appendUnsignedAsHex and appendUnsignedAsHexFixedSize so they can be reused in a function named hex for use with StringTypeAdapter. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::hex): Added. (WTF::StringTypeAdapter<HexNumberBuffer>): Added. * wtf/Logger.cpp: Added. (WTF::Logger::LogSiteIdentifier::toString const): Made this a non-template function and moved it here so that we don't need to include HexNumber.h in Logger.h. Since HexNumber.h has substantial code in it, it's good if we don't include it in any other headers. * wtf/Logger.h: (WTF::LogArgument<Logger::LogSiteIdentifier>::toString): Changed to call a non-template function, LogSiteIdentifier::toString. * wtf/text/StringConcatenateNumbers.h: Replaced overloaded writeTo functions with function templates and used StringImpl::copyCharacters instead of hand-written loops. Canonical link: https://commits.webkit.org/209182@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-19 02:04:33 +00:00
return hex(number, 0, mode);
2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
}
Continue reducing use of String::format, now focusing on hex: "%p", "%x", etc. https://bugs.webkit.org/show_bug.cgi?id=194752 Reviewed by Daniel Bates. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): Added back the "0x" that was removed when changing this file to use appendUnsignedAsHex instead of "%p". The intent at that time was to keep behavior the same, so let's do that. * parser/Lexer.cpp: (JSC::Lexer<T>::invalidCharacterMessage const): Use makeString and hex instead of String::format and "%04x". Source/WebCore: * Modules/websockets/WebSocket.cpp: Added an include of HexNumber.h. This previously got included because of Logger.h, but that no longer pulls in HexNumber.h. * css/CSSMarkup.cpp: Removed unneeded include of StringBuffer.h. * css/CSSPrimitiveValue.cpp: Ditto. * css/CSSUnicodeRangeValue.cpp: (WebCore::CSSUnicodeRangeValue::customCSSText const): Use makeString and hex instead of String::format and "%x". * html/HTMLMediaElement.h: (WTF::ValueToString<WebCore::TextTrackCue::string): Use a non-template function, TextTrackCure::debugString, so we don't need to use HextNumber.h in a header. * html/canvas/WebGLRenderingContextBase.cpp: (GetErrorString): Use makeString and hex instead of String::format and "%04x". * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::debugString const): Added. Moved string conversion here from HTMLMediaElement.h and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * html/track/TextTrackCue.h: Added TextTrackCue::debugString. * page/linux/ResourceUsageOverlayLinux.cpp: (WebCore::formatByteNumber): Use makeString and FormattedNumber::fixedWidth instead of String::format and "%.1f" etc. * platform/cocoa/KeyEventCocoa.mm: (WebCore::keyIdentifierForCharCode): Use the new hex function here instead of the old code that did each of the four characters explicitly. * platform/gamepad/mac/HIDGamepad.cpp: (WebCore::HIDGamepad::HIDGamepad): Use makeString instead of String::format. * platform/graphics/Color.cpp: (WebCore::Color::nameForRenderTreeAsText const): Use hex instead of doing each digit separately. * platform/graphics/FloatPolygon.cpp: (WebCore::FloatPolygonEdge::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * platform/graphics/FloatPolygon.h: Updated for the above. * platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::GraphicsLayerCA::setName): Use makeString instead of String::format. (WebCore::GraphicsLayerCA::recursiveCommitChanges): DItto. * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::load): Ditto. (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Ditto. * platform/gtk/PlatformKeyboardEventGtk.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForGdkKeyCode): Ditto. * platform/libwpe/PlatformKeyboardEventLibWPE.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForWPEKeyCode): Ditto. * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: (WebCore::GStreamerVideoEncoder::makeElement): Ditto. (WebCore::GStreamerVideoEncoder::InitEncode): Ditto. * platform/text/TextCodecLatin1.cpp: Removed unneeded include of StringBuffer.h and "using namespace WTF". * platform/win/GDIObjectCounter.cpp: (WebCore::GDIObjectCounter::GDIObjectCounter): Use makeString instead of String::format. * platform/win/KeyEventWin.cpp: (WebCore::keyIdentifierForWindowsKeyCode): Ditto. * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/FloatingObjects.h: Updated for the above. * rendering/RenderFragmentContainer.cpp: (WebCore::RenderFragmentContainer::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/RenderFragmentContainer.h: Updated for the above. * rendering/RenderFragmentedFlow.h: Ditto. * testing/Internals.cpp: (WebCore::Internals::address): Use makeString instead of String::format. Source/WebCore/PAL: * pal/FileSizeFormatter.cpp: (fileSizeDescription): Use makeString instead of String::format. Source/WebKit: * Platform/IPC/win/ConnectionWin.cpp: (IPC::Connection::createServerAndClientIdentifiers): Use makeString instead of String::format. * Shared/win/WebEventFactory.cpp: (WebKit::keyIdentifierFromEvent): Ditto. * UIProcess/API/APINavigation.cpp: (API::Navigation::loggingString const): Use hex instead of String::format. * UIProcess/SuspendedPageProxy.cpp: (WebKit::SuspendedPageProxy::loggingString const): Ditto. * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Added a "0x". * UIProcess/gtk/InputMethodFilter.cpp: (WebKit::InputMethodFilter::logHandleKeyboardEventForTesting): Use makeString and hex instead of String::format and "%x". (WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting): Ditto. Source/WTF: * WTF.xcodeproj/project.pbxproj: Added HexNumber.cpp and Logger.cpp. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.cpp: Added. (WTF::Internal::appendHex): Non-inline, non-template hex formatting logic. * wtf/HexNumber.h: (WTF::Internal::appendHex): Refactored main logic of appendUnsignedAsHex and appendUnsignedAsHexFixedSize so they can be reused in a function named hex for use with StringTypeAdapter. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::hex): Added. (WTF::StringTypeAdapter<HexNumberBuffer>): Added. * wtf/Logger.cpp: Added. (WTF::Logger::LogSiteIdentifier::toString const): Made this a non-template function and moved it here so that we don't need to include HexNumber.h in Logger.h. Since HexNumber.h has substantial code in it, it's good if we don't include it in any other headers. * wtf/Logger.h: (WTF::LogArgument<Logger::LogSiteIdentifier>::toString): Changed to call a non-template function, LogSiteIdentifier::toString. * wtf/text/StringConcatenateNumbers.h: Replaced overloaded writeTo functions with function templates and used StringImpl::copyCharacters instead of hand-written loops. Canonical link: https://commits.webkit.org/209182@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-19 02:04:33 +00:00
template<> class StringTypeAdapter<HexNumberBuffer> {
public:
StringTypeAdapter(const HexNumberBuffer& buffer)
: m_buffer { buffer }
{
}
unsigned length() const { return m_buffer.length; }
bool is8Bit() const { return true; }
template<typename CharacterType> void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, characters(), length()); }
private:
Further simplify StringBuilder usage by standardizing hex formating to a single hex() function https://bugs.webkit.org/show_bug.cgi?id=205759 Reviewed by Dean Jackson. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): * runtime/JSGlobalObjectFunctions.cpp: (JSC::encode): (JSC::globalFuncEscape): Replace appendUnsignedAsHex() and appendByteAsHex() with append(hex()). Source/WebCore: * Modules/websockets/WebSocket.cpp: (WebCore::encodeProtocolString): * css/CSSMarkup.cpp: (WebCore::serializeCharacterAsCodePoint): * css/parser/CSSParserToken.cpp: (WebCore::CSSParserToken::serialize const): * platform/graphics/Color.cpp: (WebCore::Color::serialized const): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::processMpegTsSection): * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: (WebCore::generateHashedName): * platform/network/curl/CurlCacheEntry.cpp: (WebCore::CurlCacheEntry::generateBaseFilename): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Replace appendByteAsHex()/appendUnsignedAsHex()/appendUnsignedAsHexFixedSize() with append(hex()). * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::appendFormURLEncoded): This was the last non-StringBuilder/makeString use of appendByteAsHex. Rather than keep appendByteAsHex around, it is replaced with direct appends of the character buffer hex() produces. Source/WebKit: * UIProcess/DeviceIdHashSaltStorage.cpp: (WebKit::DeviceIdHashSaltStorage::completeDeviceIdHashSaltForOriginCall): * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Replace appendUnsignedAsHex() with append(hex()). Source/WTF: Removes appendByteAsHex, appendUnsignedAsHex and appendUnsignedAsHexFixedSize with the following mappings: appendByteAsHex(value, builder, case) -> builder.append(hex(static_cast<unsigned char>(value), 2, case)) appendUnsignedAsHex(value, builder, case) -> builder.append(hex(value, case)) appendUnsignedAsHexFixedSize(value, builder, size, case) -> builder.append(hex(value, size, case)) Adds new API test for HexNumber.cpp * wtf/HexNumber.h: (WTF::appendByteAsHex): Deleted. (WTF::appendUnsignedAsHex): Deleted. (WTF::appendUnsignedAsHexFixedSize): Deleted. Remove now unused helper functions. * wtf/FileSystem.cpp: (WTF::FileSystemImpl::encodeForFileName): Replace appendByteAsHex with direct use of hex(x, 2). The static_cast is needed since there was an implicit down cast when appendByteAsHex was used. * wtf/Logger.cpp: (WTF::Logger::LogSiteIdentifier::toString const): (WTF::>::toString): * wtf/UUID.cpp: (WTF::createCanonicalUUIDString): Replace appendUnsignedAsHex/appendUnsignedAsHexFixedSize with hex(). Use makeString() rather StringBuilder to simplify things further. * wtf/text/WTFString.cpp: (asciiDebug): Replace appendUnsignedAsHexFixedSize with append(hex()). Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/HexNumber.cpp: Added. Add testing for hex formatting of integers. Canonical link: https://commits.webkit.org/218921@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254046 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 00:20:57 +00:00
const LChar* characters() const { return m_buffer.characters(); }
Continue reducing use of String::format, now focusing on hex: "%p", "%x", etc. https://bugs.webkit.org/show_bug.cgi?id=194752 Reviewed by Daniel Bates. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): Added back the "0x" that was removed when changing this file to use appendUnsignedAsHex instead of "%p". The intent at that time was to keep behavior the same, so let's do that. * parser/Lexer.cpp: (JSC::Lexer<T>::invalidCharacterMessage const): Use makeString and hex instead of String::format and "%04x". Source/WebCore: * Modules/websockets/WebSocket.cpp: Added an include of HexNumber.h. This previously got included because of Logger.h, but that no longer pulls in HexNumber.h. * css/CSSMarkup.cpp: Removed unneeded include of StringBuffer.h. * css/CSSPrimitiveValue.cpp: Ditto. * css/CSSUnicodeRangeValue.cpp: (WebCore::CSSUnicodeRangeValue::customCSSText const): Use makeString and hex instead of String::format and "%x". * html/HTMLMediaElement.h: (WTF::ValueToString<WebCore::TextTrackCue::string): Use a non-template function, TextTrackCure::debugString, so we don't need to use HextNumber.h in a header. * html/canvas/WebGLRenderingContextBase.cpp: (GetErrorString): Use makeString and hex instead of String::format and "%04x". * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::debugString const): Added. Moved string conversion here from HTMLMediaElement.h and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * html/track/TextTrackCue.h: Added TextTrackCue::debugString. * page/linux/ResourceUsageOverlayLinux.cpp: (WebCore::formatByteNumber): Use makeString and FormattedNumber::fixedWidth instead of String::format and "%.1f" etc. * platform/cocoa/KeyEventCocoa.mm: (WebCore::keyIdentifierForCharCode): Use the new hex function here instead of the old code that did each of the four characters explicitly. * platform/gamepad/mac/HIDGamepad.cpp: (WebCore::HIDGamepad::HIDGamepad): Use makeString instead of String::format. * platform/graphics/Color.cpp: (WebCore::Color::nameForRenderTreeAsText const): Use hex instead of doing each digit separately. * platform/graphics/FloatPolygon.cpp: (WebCore::FloatPolygonEdge::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * platform/graphics/FloatPolygon.h: Updated for the above. * platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::GraphicsLayerCA::setName): Use makeString instead of String::format. (WebCore::GraphicsLayerCA::recursiveCommitChanges): DItto. * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::load): Ditto. (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Ditto. * platform/gtk/PlatformKeyboardEventGtk.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForGdkKeyCode): Ditto. * platform/libwpe/PlatformKeyboardEventLibWPE.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForWPEKeyCode): Ditto. * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: (WebCore::GStreamerVideoEncoder::makeElement): Ditto. (WebCore::GStreamerVideoEncoder::InitEncode): Ditto. * platform/text/TextCodecLatin1.cpp: Removed unneeded include of StringBuffer.h and "using namespace WTF". * platform/win/GDIObjectCounter.cpp: (WebCore::GDIObjectCounter::GDIObjectCounter): Use makeString instead of String::format. * platform/win/KeyEventWin.cpp: (WebCore::keyIdentifierForWindowsKeyCode): Ditto. * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/FloatingObjects.h: Updated for the above. * rendering/RenderFragmentContainer.cpp: (WebCore::RenderFragmentContainer::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/RenderFragmentContainer.h: Updated for the above. * rendering/RenderFragmentedFlow.h: Ditto. * testing/Internals.cpp: (WebCore::Internals::address): Use makeString instead of String::format. Source/WebCore/PAL: * pal/FileSizeFormatter.cpp: (fileSizeDescription): Use makeString instead of String::format. Source/WebKit: * Platform/IPC/win/ConnectionWin.cpp: (IPC::Connection::createServerAndClientIdentifiers): Use makeString instead of String::format. * Shared/win/WebEventFactory.cpp: (WebKit::keyIdentifierFromEvent): Ditto. * UIProcess/API/APINavigation.cpp: (API::Navigation::loggingString const): Use hex instead of String::format. * UIProcess/SuspendedPageProxy.cpp: (WebKit::SuspendedPageProxy::loggingString const): Ditto. * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Added a "0x". * UIProcess/gtk/InputMethodFilter.cpp: (WebKit::InputMethodFilter::logHandleKeyboardEventForTesting): Use makeString and hex instead of String::format and "%x". (WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting): Ditto. Source/WTF: * WTF.xcodeproj/project.pbxproj: Added HexNumber.cpp and Logger.cpp. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.cpp: Added. (WTF::Internal::appendHex): Non-inline, non-template hex formatting logic. * wtf/HexNumber.h: (WTF::Internal::appendHex): Refactored main logic of appendUnsignedAsHex and appendUnsignedAsHexFixedSize so they can be reused in a function named hex for use with StringTypeAdapter. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::hex): Added. (WTF::StringTypeAdapter<HexNumberBuffer>): Added. * wtf/Logger.cpp: Added. (WTF::Logger::LogSiteIdentifier::toString const): Made this a non-template function and moved it here so that we don't need to include HexNumber.h in Logger.h. Since HexNumber.h has substantial code in it, it's good if we don't include it in any other headers. * wtf/Logger.h: (WTF::LogArgument<Logger::LogSiteIdentifier>::toString): Changed to call a non-template function, LogSiteIdentifier::toString. * wtf/text/StringConcatenateNumbers.h: Replaced overloaded writeTo functions with function templates and used StringImpl::copyCharacters instead of hand-written loops. Canonical link: https://commits.webkit.org/209182@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-19 02:04:33 +00:00
const HexNumberBuffer& m_buffer;
};
[JSC] Improve Wasm binary test coverage https://bugs.webkit.org/show_bug.cgi?id=204843 Reviewed by Darin Adler. JSTests: * wasm/function-tests/grow-memory.js: (binaryShouldNotParse): * wasm/spec-tests/binary-leb128.wast.js: * wasm/spec-tests/binary.wast.js: * wasm/wasm.json: Source/JavaScriptCore: This patch fixes some of bugs in wasm parser so that we validate malformed wasm modules more strictly. 1. current_memory / grow_memory should have uint8 flag, not varuint32 flag. 2. global section should have uint8 mutability information, not varuint32. 3. memory section should have varuint32 memory count. * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseResizableLimits): (JSC::Wasm::SectionParser::parseMemory): (JSC::Wasm::SectionParser::parseGlobalType): * wasm/wasm.json: Source/WTF: LEBDecoder should have more strict validation. One thing is that, we should reject pattern that includes ignored bits. For example, in uint32_t, we can represent UINT32_MAX in 5 bytes like this. 0xff, 0xff, 0xff, 0xff, 0x0f 0b1111111_1111111_1111111_1111111_1111 Leading bytes has 0x80 trailing marker. And they includes each 7 bit slice. And the last byte includes 0b1111 part. But we can also make it in the following form 0xff, 0xff, 0xff, 0xff, 0xff 0b1111111_1111111_1111111_1111111_1111 In the above case, the last byte's upper 4 bits are ignored in the result, and this is wrong in LEB128 encoding. We should reject this input since the last byte includes overflown bits. This patch adds this validation to WTF. * wtf/LEBDecoder.h: (WTF::LEBDecoder::maxByteLength): (WTF::LEBDecoder::lastByteMask): (WTF::LEBDecoder::decodeUInt): (WTF::LEBDecoder::decodeInt): Tools: We add more tests for LEBDecoder. In particular, the added tests focus on the case which overflow bits. * TestWebKitAPI/Tests/WTF/LEBDecoder.cpp: (TestWebKitAPI::toString): (TestWebKitAPI::testUInt32LEBDecode): (TestWebKitAPI::TEST): (TestWebKitAPI::testUInt64LEBDecode): (TestWebKitAPI::testInt32LEBDecode): (TestWebKitAPI::testInt64LEBDecode): Canonical link: https://commits.webkit.org/231741@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269998 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-11-18 23:50:34 +00:00
class PrintStream;
WTF_EXPORT_PRIVATE void printInternal(PrintStream&, HexNumberBuffer);
2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
} // namespace WTF
Continue reducing use of String::format, now focusing on hex: "%p", "%x", etc. https://bugs.webkit.org/show_bug.cgi?id=194752 Reviewed by Daniel Bates. Source/JavaScriptCore: * heap/HeapSnapshotBuilder.cpp: (JSC::HeapSnapshotBuilder::json): Added back the "0x" that was removed when changing this file to use appendUnsignedAsHex instead of "%p". The intent at that time was to keep behavior the same, so let's do that. * parser/Lexer.cpp: (JSC::Lexer<T>::invalidCharacterMessage const): Use makeString and hex instead of String::format and "%04x". Source/WebCore: * Modules/websockets/WebSocket.cpp: Added an include of HexNumber.h. This previously got included because of Logger.h, but that no longer pulls in HexNumber.h. * css/CSSMarkup.cpp: Removed unneeded include of StringBuffer.h. * css/CSSPrimitiveValue.cpp: Ditto. * css/CSSUnicodeRangeValue.cpp: (WebCore::CSSUnicodeRangeValue::customCSSText const): Use makeString and hex instead of String::format and "%x". * html/HTMLMediaElement.h: (WTF::ValueToString<WebCore::TextTrackCue::string): Use a non-template function, TextTrackCure::debugString, so we don't need to use HextNumber.h in a header. * html/canvas/WebGLRenderingContextBase.cpp: (GetErrorString): Use makeString and hex instead of String::format and "%04x". * html/track/TextTrackCue.cpp: (WebCore::TextTrackCue::debugString const): Added. Moved string conversion here from HTMLMediaElement.h and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * html/track/TextTrackCue.h: Added TextTrackCue::debugString. * page/linux/ResourceUsageOverlayLinux.cpp: (WebCore::formatByteNumber): Use makeString and FormattedNumber::fixedWidth instead of String::format and "%.1f" etc. * platform/cocoa/KeyEventCocoa.mm: (WebCore::keyIdentifierForCharCode): Use the new hex function here instead of the old code that did each of the four characters explicitly. * platform/gamepad/mac/HIDGamepad.cpp: (WebCore::HIDGamepad::HIDGamepad): Use makeString instead of String::format. * platform/graphics/Color.cpp: (WebCore::Color::nameForRenderTreeAsText const): Use hex instead of doing each digit separately. * platform/graphics/FloatPolygon.cpp: (WebCore::FloatPolygonEdge::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * platform/graphics/FloatPolygon.h: Updated for the above. * platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::GraphicsLayerCA::setName): Use makeString instead of String::format. (WebCore::GraphicsLayerCA::recursiveCommitChanges): DItto. * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::load): Ditto. (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Ditto. * platform/gtk/PlatformKeyboardEventGtk.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForGdkKeyCode): Ditto. * platform/libwpe/PlatformKeyboardEventLibWPE.cpp: (WebCore::PlatformKeyboardEvent::keyIdentifierForWPEKeyCode): Ditto. * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: (WebCore::GStreamerVideoEncoder::makeElement): Ditto. (WebCore::GStreamerVideoEncoder::InitEncode): Ditto. * platform/text/TextCodecLatin1.cpp: Removed unneeded include of StringBuffer.h and "using namespace WTF". * platform/win/GDIObjectCounter.cpp: (WebCore::GDIObjectCounter::GDIObjectCounter): Use makeString instead of String::format. * platform/win/KeyEventWin.cpp: (WebCore::keyIdentifierForWindowsKeyCode): Ditto. * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/FloatingObjects.h: Updated for the above. * rendering/RenderFragmentContainer.cpp: (WebCore::RenderFragmentContainer::debugString const): Added. Moved string conversion here from the header and use makeString instead of String::format. Also use the word "debug" to make it clear that it's not OK to use this string, with a pointer value serialized into it, outside of debugging. * rendering/RenderFragmentContainer.h: Updated for the above. * rendering/RenderFragmentedFlow.h: Ditto. * testing/Internals.cpp: (WebCore::Internals::address): Use makeString instead of String::format. Source/WebCore/PAL: * pal/FileSizeFormatter.cpp: (fileSizeDescription): Use makeString instead of String::format. Source/WebKit: * Platform/IPC/win/ConnectionWin.cpp: (IPC::Connection::createServerAndClientIdentifiers): Use makeString instead of String::format. * Shared/win/WebEventFactory.cpp: (WebKit::keyIdentifierFromEvent): Ditto. * UIProcess/API/APINavigation.cpp: (API::Navigation::loggingString const): Use hex instead of String::format. * UIProcess/SuspendedPageProxy.cpp: (WebKit::SuspendedPageProxy::loggingString const): Ditto. * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::loggingString): Added a "0x". * UIProcess/gtk/InputMethodFilter.cpp: (WebKit::InputMethodFilter::logHandleKeyboardEventForTesting): Use makeString and hex instead of String::format and "%x". (WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting): Ditto. Source/WTF: * WTF.xcodeproj/project.pbxproj: Added HexNumber.cpp and Logger.cpp. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.cpp: Added. (WTF::Internal::appendHex): Non-inline, non-template hex formatting logic. * wtf/HexNumber.h: (WTF::Internal::appendHex): Refactored main logic of appendUnsignedAsHex and appendUnsignedAsHexFixedSize so they can be reused in a function named hex for use with StringTypeAdapter. (WTF::appendUnsignedAsHex): Ditto. (WTF::appendUnsignedAsHexFixedSize): Ditto. (WTF::hex): Added. (WTF::StringTypeAdapter<HexNumberBuffer>): Added. * wtf/Logger.cpp: Added. (WTF::Logger::LogSiteIdentifier::toString const): Made this a non-template function and moved it here so that we don't need to include HexNumber.h in Logger.h. Since HexNumber.h has substantial code in it, it's good if we don't include it in any other headers. * wtf/Logger.h: (WTF::LogArgument<Logger::LogSiteIdentifier>::toString): Changed to call a non-template function, LogSiteIdentifier::toString. * wtf/text/StringConcatenateNumbers.h: Replaced overloaded writeTo functions with function templates and used StringImpl::copyCharacters instead of hand-written loops. Canonical link: https://commits.webkit.org/209182@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-19 02:04:33 +00:00
using WTF::hex;
2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * GNUmakefile.am: Add HexNumber.h to build. * JavaScriptCore.exp: Export StringBuilder::reserveCapacity. * JavaScriptCore.gypi: Add HexNumber.h to build. * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export StringBuilder::reserveCapacity. * JavaScriptCore.vcproj/WTF/WTF.vcproj: Add HexNumber.h to build. * JavaScriptCore.xcodeproj/project.pbxproj: Ditto. * wtf/CMakeLists.txt: Ditto. * wtf/HexNumber.h: Added. (WTF::Internal::hexDigitsForMode): Internal helper. (WTF::appendByteAsHex): Free function, that appends a byte as hex string into a destination. (WTF::placeByteAsHex): Ditto, but places the result using *foo++ = '..' or foo[index++] = '..' (WTF::appendUnsignedAsHex): Free function, that appends a number as hex string into a destination. 2011-03-24 Nikolas Zimmermann <nzimmermann@rim.com> Reviewed by Darin Adler. Introduce WTF HexNumber.h https://bugs.webkit.org/show_bug.cgi?id=56099 Introduce a set of functions that ease converting from a bye or a number to a hex string, replacing several of these conversions and String::format("%x") usages all over WebCore. * ForwardingHeaders/wtf/HexNumber.h: Added. * css/CSSOMUtils.cpp: (WebCore::serializeCharacterAsCodePoint): * css/CSSParser.cpp: (WebCore::quoteCSSString): * inspector/InspectorResourceAgent.cpp: (WebCore::createReadableStringFromBinary): * platform/FileSystem.cpp: (WebCore::encodeForFileName): * platform/KURL.cpp: (WebCore::appendEscapedChar): * platform/UUID.cpp: (WebCore::createCanonicalUUIDString): * platform/graphics/Color.cpp: (WebCore::Color::serialized): * platform/network/FormDataBuilder.cpp: (WebCore::FormDataBuilder::encodeStringAsFormData): * rendering/RenderTreeAsText.cpp: (WebCore::quoteAndEscapeNonPrintables): Canonical link: https://commits.webkit.org/71751@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@81943 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2011-03-25 06:35:51 +00:00
using WTF::Lowercase;