SerializedScriptValue should use a compact encoding for 8-bit strings.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Oct 2015 15:27:46 +0000 (15:27 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Oct 2015 15:27:46 +0000 (15:27 +0000)
commit687603454cbf4d66db4a095105255d49bb7907e2
tree69db1e0d49cdc54d1b5c340180300734fed5673e
parentd50bf5aef3b3fcb06677fcd61a46d5142524aa23
SerializedScriptValue should use a compact encoding for 8-bit strings.
<https://webkit.org/b/149934>

Reviewed by Antti Koivisto.

Source/WebCore:

We were encoding known 8-bit strings in a 16-bit format when serializing script values.

Extend the format to support 8-bit strings. The 8-bittiness is encoded in the highest bit
of the string length. This is possible while supporting all older formats due to string
lengths >= 0x7FFFFFFF being disallowed.

This patch knocks ~1 MB off of theverge.com, where some ad or tracker or whatever likes to
do a ton of postMessage() business.

* bindings/js/SerializedScriptValue.cpp:
(WebCore::CurrentVersion): Bump the serialization format version. Also updated the grammar
comment to describe the new format. Artistic license applied in description of bitfield.

(WebCore::writeLittleEndianUInt16): Deleted.

(WebCore::CloneSerializer::serialize):
(WebCore::CloneSerializer::write):
(WebCore::CloneDeserializer::deserializeString):
(WebCore::CloneDeserializer::readString):
(WebCore::CloneDeserializer::readStringData): Support 8-bit strings. I kept the string
length limit at UINT_MAX/sizeof(UChar) since the highest bit of the length is no longer
available. Besides, it seems flimsy to support longer strings if they happen to have all
8-bit characters.

LayoutTests:

Update a test to reflect changes to the serialization format.

* fast/storage/serialized-script-value.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190838 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/storage/serialized-script-value.html
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/SerializedScriptValue.cpp