Optimize serialization of quoted JSON strings.
<https://webkit.org/b/144754>
Reviewed by Darin Adler.
Source/JavaScriptCore:
Optimized the serialization of quoted strings into JSON by moving the logic into
StringBuilder so it can make smarter decisions about buffering.
12% progression on Kraken/json-stringify-tinderbox (on my Mac Pro.)
* bytecompiler/NodesCodegen.cpp:
(JSC::ObjectPatternNode::toString): Use the new StringBuilder API.
* runtime/JSONObject.h:
* runtime/JSONObject.cpp:
(JSC::Stringifier::Holder::appendNextProperty):
(JSC::appendStringToStringBuilder): Deleted.
(JSC::appendQuotedJSONStringToBuilder): Deleted.
(JSC::Stringifier::appendQuotedString): Deleted.
(JSC::Stringifier::appendStringifiedValue): Moved the bulk of this logic
to StringBuilder and call that from here.
Source/WebKit2:
* NetworkProcess/cache/NetworkCacheEntry.cpp:
(WebKit::NetworkCache::Entry::asJSON): Use the new StringBuilder API.
Source/WTF:
Add a StringBuilder API for appending a quoted JSON string. This is used by
JSON.stringify() to implement efficient appending of strings while escaping
quotes, control characters and \uNNNN-style characters.
The main benefit comes from only doing a single buffer expansion up front,
instead of doing it every time we append something. The fudge factor is pretty
large, since the maximum number of output characters per input character is 6.
The first landing of this patch had two bugs in it:
- Made \uNNNN escapes uppercase hexadecimal instead of lowercase.
- Didn't preallocate enough space for 8-bit input strings.
Both were caught by existing tests on our bots, and both were due to last-minute
changes before landing. :/
* wtf/text/StringBuilder.cpp:
(WTF::appendQuotedJSONStringInternal):
(WTF::StringBuilder::appendQuotedJSONString):
* wtf/text/StringBuilder.h:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183988
268f45cc-cd09-0410-ab3c-
d52691b4dbfc