summaryrefslogtreecommitdiff
path: root/core/io/compression.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/compression.cpp')
-rw-r--r--core/io/compression.cpp19
1 files changed, 6 insertions, 13 deletions
diff --git a/core/io/compression.cpp b/core/io/compression.cpp
index 20c9fdca6f..99ca8107e4 100644
--- a/core/io/compression.cpp
+++ b/core/io/compression.cpp
@@ -40,10 +40,8 @@
#include <zstd.h>
int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode) {
-
switch (p_mode) {
case MODE_FASTLZ: {
-
if (p_src_size < 16) {
uint8_t src[16];
zeromem(&src[p_src_size], 16 - p_src_size);
@@ -56,7 +54,6 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
-
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
@@ -65,8 +62,9 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
strm.opaque = Z_NULL;
int level = p_mode == MODE_DEFLATE ? zlib_level : gzip_level;
int err = deflateInit2(&strm, level, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY);
- if (err != Z_OK)
+ if (err != Z_OK) {
return -1;
+ }
strm.avail_in = p_src_size;
int aout = deflateBound(&strm, p_src_size);
@@ -97,19 +95,17 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
}
int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
-
switch (p_mode) {
case MODE_FASTLZ: {
-
int ss = p_src_size + p_src_size * 6 / 100;
- if (ss < 66)
+ if (ss < 66) {
ss = 66;
+ }
return ss;
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
-
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
@@ -117,14 +113,14 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
strm.zfree = zipio_free;
strm.opaque = Z_NULL;
int err = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY);
- if (err != Z_OK)
+ if (err != Z_OK) {
return -1;
+ }
int aout = deflateBound(&strm, p_src_size);
deflateEnd(&strm);
return aout;
} break;
case MODE_ZSTD: {
-
return ZSTD_compressBound(p_src_size);
} break;
}
@@ -133,10 +129,8 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
}
int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode) {
-
switch (p_mode) {
case MODE_FASTLZ: {
-
int ret_size = 0;
if (p_dst_max_size < 16) {
@@ -150,7 +144,6 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
-
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;