You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d24e80e
Browse filesBrowse the repository at this point in the historyBrowse files
[JSC] JSON.parse should convert doubles without scanning them twice
https://bugs.webkit.org/show_bug.cgi?id=329545
rdar://191382963
Reviewed by Keith Miller.
lexNumber scanned the integer part of a number, then handed anything with a fraction, an exponent, or
more than nine digits to WTF::parseJSONDouble, which scanned it again from the start.
This patch finishes the scan in place with scanJSONDecimal, reading fraction digits eight at a time for
both 8-bit and 16-bit sources, and converts the result directly: a single exact multiplication or division
for at most 15 digits and a small exponent, and fast_float's compute_float otherwise. Numbers with more
than 19 significant digits and malformed numbers still go to WTF::parseJSONDouble, so results and error
messages are unchanged. The loop over cached keys uses the same scan for doubles and long integers.
Tests: JSTests/stress/json-parse-cached-number-values.js
JSTests/stress/json-parse-doubles.js
Tools/TestWebKitAPI/Tests/WTF/FastFloat.cpp
* JSTests/stress/json-parse-cached-number-values.js: Renamed from JSTests/stress/json-parse-cached-integer-values.js.
* JSTests/stress/json-parse-doubles-near-halfway.js: Added.
(shouldBe):
(rand):
(midpointDigits):
(join):
* JSTests/stress/json-parse-doubles.js: Added.
(shouldBe):
(rand):
(parseObjects):
(length.string_appeared_here.catch):
* Source/JavaScriptCore/runtime/LiteralParser.cpp:
(JSC::scanJSONIntegerDigits):
(JSC::scanJSONDecimal):
(JSC::reviverMode>::Lexer::lexNumber):
(JSC::reviverMode>::Lexer::lexDouble):
(JSC::requires):
* Source/JavaScriptCore/runtime/LiteralParser.h:
* Source/WTF/wtf/FastFloat.cpp:
(WTF::parseJSONDoubleFromDigitsSlow):
* Source/WTF/wtf/FastFloat.h:
(WTF::parseJSONDoubleFromDigits):
* Source/WTF/wtf/SIMDHelpers.h:
(WTF::SIMD::loadAndSaturateNarrowToU64):
* Tools/TestWebKitAPI/CMakeLists.txt:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WTF/FastFloat.cpp: Added.
(TestWebKitAPI::expectSameAsParseJSONDouble):
(TestWebKitAPI::TEST(WTF_FastFloat, ParseJSONDoubleFromDigits)):
Canonical link: https://commits.webkit.org/325669@main
0 commit comments