From f28bd1972fd96cea476d537fe1b9b5953473161a Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 21 Feb 2019 00:52:47 -0500 Subject: [PATCH] Adjust LZ4F block size --- native/jni/magiskboot/compress.cpp | 4 ++-- native/jni/magiskboot/compress.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/native/jni/magiskboot/compress.cpp b/native/jni/magiskboot/compress.cpp index b93c8e844..b46fe8c87 100644 --- a/native/jni/magiskboot/compress.cpp +++ b/native/jni/magiskboot/compress.cpp @@ -410,7 +410,7 @@ bool LZ4FEncoder::update(const void *in, size_t size) { auto inbuf = (const uint8_t *) in; size_t read, write; do { - read = size > CHUNK ? CHUNK : size; + read = size > BLOCK_SZ ? BLOCK_SZ : size; write = LZ4F_compressUpdate(ctx, outbuf, outCapacity, inbuf, read, nullptr); if (LZ4F_isError(write)) { LOGW("LZ4 encode error: %s\n", LZ4F_getErrorName(write)); @@ -442,7 +442,7 @@ void LZ4FEncoder::write_header() { .contentChecksumFlag = LZ4F_contentChecksumEnabled } }; - outCapacity = LZ4F_compressBound(CHUNK, &prefs); + outCapacity = LZ4F_compressBound(BLOCK_SZ, &prefs); outbuf = new uint8_t[outCapacity]; size_t write = LZ4F_compressBegin(ctx, outbuf, outCapacity, &prefs); total += write; diff --git a/native/jni/magiskboot/compress.h b/native/jni/magiskboot/compress.h index 7529915c1..e83e78768 100644 --- a/native/jni/magiskboot/compress.h +++ b/native/jni/magiskboot/compress.h @@ -140,6 +140,7 @@ public: uint64_t finalize() override; private: + static constexpr size_t BLOCK_SZ = 1 << 22; LZ4F_compressionContext_t ctx; uint8_t *outbuf; size_t outCapacity;