зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1828654 - Move deflateInit before deflateBound r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D196224
This commit is contained in:
Родитель
9bec24e579
Коммит
f046fa90a2
|
@ -94,6 +94,18 @@ bool ScriptBytecodeCompress(Vector<uint8_t>& aBytecodeBuf,
|
|||
uncompressedLength = uncompressedLayout.bytecodeLength();
|
||||
z_stream zstream{.next_in = uncompressedLayout.bytecode(),
|
||||
.avail_in = uncompressedLength};
|
||||
|
||||
// Note: deflateInit needs to be called before deflateBound.
|
||||
const uint32_t compressionLevel =
|
||||
StaticPrefs::browser_cache_jsbc_compression_level();
|
||||
if (deflateInit(&zstream, compressionLevel) != Z_OK) {
|
||||
LOG(
|
||||
("ScriptLoadRequest: Unable to initialize bytecode cache "
|
||||
"compression."));
|
||||
return false;
|
||||
}
|
||||
auto autoDestroy = MakeScopeExit([&]() { deflateEnd(&zstream); });
|
||||
|
||||
auto compressedLength = deflateBound(&zstream, uncompressedLength);
|
||||
if (!aCompressedBytecodeBufOut.resizeUninitialized(
|
||||
compressedLength + compressedLayout.preludeLength() +
|
||||
|
@ -107,16 +119,6 @@ bool ScriptBytecodeCompress(Vector<uint8_t>& aBytecodeBuf,
|
|||
zstream.next_out = compressedLayout.bytecode();
|
||||
zstream.avail_out = compressedLength;
|
||||
|
||||
const uint32_t compressionLevel =
|
||||
StaticPrefs::browser_cache_jsbc_compression_level();
|
||||
if (deflateInit(&zstream, compressionLevel) != Z_OK) {
|
||||
LOG(
|
||||
("ScriptLoadRequest: Unable to initialize bytecode cache "
|
||||
"compression."));
|
||||
return false;
|
||||
}
|
||||
auto autoDestroy = MakeScopeExit([&]() { deflateEnd(&zstream); });
|
||||
|
||||
int ret = deflate(&zstream, Z_FINISH);
|
||||
if (ret == Z_MEM_ERROR) {
|
||||
return false;
|
||||
|
|
Загрузка…
Ссылка в новой задаче