[webkit-changes] [WebKit/WebKit] 058660: Fix more NumberToStringBuffer conversions to use s...
Commit Queue
noreply at github.com
Mon Oct 21 10:53:15 PDT 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 058660103448a14477572e3509a632991934c777
https://github.com/WebKit/WebKit/commit/058660103448a14477572e3509a632991934c777
Author: David Kilzer <ddkilzer at apple.com>
Date: 2024-10-21 (Mon, 21 Oct 2024)
Changed paths:
M Source/JavaScriptCore/runtime/NumberPrototype.cpp
M Source/JavaScriptCore/runtime/PropertyName.h
M Source/WTF/wtf/dragonbox/dragonbox_to_chars.h
M Source/WTF/wtf/dtoa.cpp
M Source/WTF/wtf/dtoa.h
M Source/WTF/wtf/dtoa/double-conversion.cc
M Source/WTF/wtf/dtoa/utils.h
M Source/WTF/wtf/text/AtomString.cpp
M Source/WTF/wtf/text/StringConcatenateNumbers.h
M Source/WTF/wtf/text/WTFString.cpp
M Source/WebCore/platform/Decimal.cpp
M Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp
M Tools/TestWebKitAPI/Tests/WTF/DragonBoxTest.cpp
Log Message:
-----------
Fix more NumberToStringBuffer conversions to use std::span
<https://bugs.webkit.org/show_bug.cgi?id=280596>
<rdar://136944262>
Reviewed by Dan Glastonbury, Darin Adler, and Mike Wyrzykowski.
Updating WTF::numberTo...String...() functions in dtoa.{cpp,h} to return
std::span values frequently eliminates a call to strlen() to get the
length of the C-string bytes stored in the std::array.
* Source/JavaScriptCore/runtime/NumberPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION(numberProtoFuncToExponential, ...)):
- Stop calling String::fromLatin1() since StringBuilder::Finalize()
returns a std::span now. Eliminates a call to strlen().
* Source/JavaScriptCore/runtime/PropertyName.h:
(JSC::isCanonicalNumericIndexString):
- Simplify now that WTF::numberToStringAndSize() returns std::span.
* Source/WTF/wtf/dragonbox/dragonbox_to_chars.h:
(WTF::dragonbox::ToExponential):
(WTF::dragonbox::ToShortest):
- Change ASSERT() to static_assert() when possible to catch bugs
earlier.
* Source/WTF/wtf/dtoa.cpp:
(WTF::numberToStringAndSize):
(WTF::numberToStringWithTrailingPoint):
(WTF::numberToFixedPrecisionString):
(WTF::numberToFixedWidthString):
(WTF::numberToCSSString):
- Update to return std::span.
* Source/WTF/wtf/dtoa.h:
(WTF::numberToStringAndSize):
(WTF::numberToStringWithTrailingPoint):
(WTF::numberToFixedPrecisionString):
(WTF::numberToFixedWidthString):
(WTF::numberToCSSString):
- Add LIFETIME_BOUND attribute since std::span return value depends on
the lifetime of the NumberToStringBuffer& argument.
- Update to return std::span.
* Source/WTF/wtf/dtoa/double-conversion.cc:
(WTF::double_conversion::DoubleToStringConverter::CreateExponentialRepresentation):
- Make sure length is always valid.
- Change while() loop to check value of first_char_pos as well.
(WTF::double_conversion::DoubleToStringConverter::CreateDecimalRepresentation):
(WTF::double_conversion::DoubleToStringConverter::ToShortestIeeeNumber):
(WTF::double_conversion::DoubleToStringConverter::ToFixed):
(WTF::double_conversion::DoubleToStringConverter::ToFixedUncapped):
(WTF::double_conversion::DoubleToStringConverter::ToExponential):
(WTF::double_conversion::DoubleToStringConverter::ToPrecision):
(WTF::double_conversion::StringToIeee):
- Change `const int` buffer lengths to `constexpr size_t`.
- Change ASSERT() to static_assert() when possible to catch bugs
earlier.
- Change ASSERT() to ASSERT_WITH_SECURITY_IMPLICATION() to catch bugs.
* Source/WTF/wtf/dtoa/utils.h:
(WTF::double_conversion::StrLength):
(WTF::double_conversion::BufferReference::BufferReference):
(WTF::double_conversion::BufferReference::SubBufferReference):
(WTF::double_conversion::BufferReference::operator[] const):
(WTF::double_conversion::StringBuilder::position const):
(WTF::double_conversion::StringBuilder::AddCharacter):
(WTF::double_conversion::StringBuilder::AddSubstring):
(WTF::double_conversion::StringBuilder::RemoveCharacters):
- Change ASSERT() to ASSERT_WITH_SECURITY_IMPLICATION() to catch bugs.
(WTF::double_conversion::StringBuilder::Finalize):
- Never write out-of-bounds even if position_ is negative.
- Change to return std::span instead of pointer.
* Source/WTF/wtf/text/AtomString.cpp:
(WTF::AtomString::number):
- Simplify now that WTF::numberToStringAndSize() returns std::span.
* Source/WTF/wtf/text/StringConcatenateNumbers.h:
(WTF::StringTypeAdapter::StringTypeAdapter):
(WTF::FormattedNumber::fixedPrecision):
(WTF::FormattedNumber::fixedWidth):
(WTF::FormattedCSSNumber::create):
- Set m_length from std::span::size().
* Source/WTF/wtf/text/WTFString.cpp:
(WTF::String::number):
* Source/WebCore/platform/Decimal.cpp:
(WebCore::Decimal::fromDouble):
- Simplify now that WTF::numberToStringAndSize() returns std::span.
* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
(WGSL::Metal::FunctionDefinitionWriter::serializeConstant):
- Simplify now that WTF::numberToStringAndSize() returns std::span.
- Avoiding use of WTF::span(const char*) eliminates a call to strlen().
* Tools/TestWebKitAPI/Tests/WTF/DragonBoxTest.cpp:
(TestWebKitAPI::DragonBoxTest::dragonBoxToString):
(TestWebKitAPI::DragonBoxTest::dragonBoxToExponential):
(TestWebKitAPI::DragonBoxTest::doubleConversionToString):
(TestWebKitAPI::DragonBoxTest::doubleConversionToExponential):
- Update for std::span returned from StringBuilder::Finalize() method.
- Assert that length returned from Finalize() matches strlen() of the
buffer backed by the std::array.
Canonical link: https://commits.webkit.org/285520@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list