Skip to content

Commit

Permalink
[JSC] Add fallback FastStringifier for 16-bit strings
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=260924
rdar://114723262

Reviewed by Mark Lam.

This patch enhances FastStringifier to accept 16-bit strings.
We make it FastStringifier<CharType>, and keep it the previous 8-bit strings fast path.
And we fall back to FastStringifier<UChar> only when the following conditions are met.

    1. We failed due to 16-bit string.
    2. The content is filled less than 50% of the buffer.

We also adjust bufferSize from 6000 to 8192. The previous value comes from Speedometer2.1.
The new value comes from Speedometer3. And we also support undefined property skipping in the FastStringifier.

* JSTests/stress/json-undefined-prop-skip.js: Added.
(shouldBe):
(shouldBe.JSON.stringify):
* Source/JavaScriptCore/runtime/JSONObject.cpp:
(JSC::JSONObject::JSONObject):
(JSC::FastStringifier<CharType>::logOutcome):
(JSC::logOutcomeImpl):
(JSC::FastStringifier<CharType>::usableBufferSize):
(JSC::FastStringifier<CharType>::FastStringifier):
(JSC::FastStringifier<CharType>::haveFailure const):
(JSC::FastStringifier<CharType>::result const):
(JSC::FastStringifier<CharType>::recordFailure):
(JSC::FastStringifier<CharType>::recordBufferFull):
(JSC::FastStringifier<CharType>::hasRemainingCapacity):
(JSC::FastStringifier<CharType>::hasRemainingCapacitySlow):
(JSC::FastStringifier<CharType>::recordFastPropertyEnumerationFailure):
(JSC::FastStringifier<CharType>::firstGetterSetterPropertyName const):
(JSC::FastStringifier<CharType>::mayHaveToJSON const):
(JSC::FastStringifier<CharType>::append):
(JSC::FastStringifier<CharType>::stringify):
(JSC::stringify):
(JSC::FastStringifier::logOutcome): Deleted.
(JSC::FastStringifier::usableBufferSize): Deleted.
(JSC::FastStringifier::FastStringifier): Deleted.
(JSC::FastStringifier::haveFailure const): Deleted.
(JSC::FastStringifier::result const): Deleted.
(JSC::FastStringifier::recordFailure): Deleted.
(JSC::FastStringifier::recordBufferFull): Deleted.
(JSC::FastStringifier::hasRemainingCapacity): Deleted.
(JSC::FastStringifier::hasRemainingCapacitySlow): Deleted.
(JSC::FastStringifier::recordFastPropertyEnumerationFailure): Deleted.
(JSC::FastStringifier::firstGetterSetterPropertyName const): Deleted.
(JSC::FastStringifier::mayHaveToJSON const): Deleted.
(JSC::FastStringifier::append): Deleted.
(JSC::FastStringifier::stringify): Deleted.

Canonical link: https://commits.webkit.org/267481@main
  • Loading branch information
Constellation committed Aug 31, 2023
1 parent 3088454 commit f5cf4d7
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 64 deletions.
8 changes: 8 additions & 0 deletions JSTests/stress/json-undefined-prop-skip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}

shouldBe(JSON.stringify({
hello: undefined
}), `{}`);

0 comments on commit f5cf4d7

Please sign in to comment.