27 static_assert(
sizeof(Bytef) == 1,
"");
28 const uLongf input_size =
29 static_cast<uLongf
>(uncompressed_data->
RawData().
size());
30 uint32_t payload_length =
31 static_cast<uint32_t
>(uncompressed_data->
RawData().
size());
33 uLongf compressed_data_size = compressBound(input_size);
37 static_cast<uint32_t
>(
sizeof(payload_length) + compressed_data_size));
39 uint8_t* compressed_data =
40 const_cast<uint8_t*
>(snapshot_data.
RawData().begin());
43 MemCopy(compressed_data, &payload_length,
sizeof(payload_length));
46 zlib_internal::CompressHelper(
47 zlib_internal::ZRAW, compressed_data +
sizeof(payload_length),
48 &compressed_data_size,
49 reinterpret_cast<const Bytef*
>(uncompressed_data->
RawData().
begin()),
50 input_size, Z_DEFAULT_COMPRESSION,
nullptr,
nullptr),
54 snapshot_data.
Resize(
static_cast<uint32_t
>(compressed_data_size) +
55 sizeof(payload_length));
59 if (
v8_flags.profile_deserialization) {
60 double ms = timer.Elapsed().InMillisecondsF();
61 PrintF(
"[Compressing %d bytes took %0.3f ms]\n", payload_length, ms);
72 const Bytef* input_bytef =
73 reinterpret_cast<const Bytef*
>(compressed_data.
begin());
78 input_bytef +=
sizeof(uncompressed_payload_length);
82 uLongf uncompressed_size = uncompressed_payload_length;
83 CHECK_EQ(zlib_internal::UncompressHelper(
86 &uncompressed_size, input_bytef,
87 static_cast<uLong
>(compressed_data.
size() -
88 sizeof(uncompressed_payload_length))),
91 if (
v8_flags.profile_deserialization) {
92 double ms = timer.Elapsed().InMillisecondsF();
93 PrintF(
"[Decompressing %d bytes took %0.3f ms]\n",
94 uncompressed_payload_length, ms);