diff options
author | Alexander Færøy <ahf@torproject.org> | 2017-04-24 14:20:16 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-04-25 08:11:32 -0400 |
commit | cf912259ba491e51f6f211e186ff67605ff269c8 (patch) | |
tree | 95878575ea7820970da112a3574708413bc11d6e /src/common/compress_zlib.c | |
parent | 69a41e8bc6e148c471ae8ee860e1a43548729db0 (diff) | |
download | tor-cf912259ba491e51f6f211e186ff67605ff269c8.tar.gz tor-cf912259ba491e51f6f211e186ff67605ff269c8.zip |
Remove `tor_compress_memory_level()`.
This patch splits up `tor_compress_memory_level()` into static functions
in the individual compression backends, which allows us to tune the
values per compression backend rather than globally.
See: https://bugs.torproject.org/21662
Diffstat (limited to 'src/common/compress_zlib.c')
-rw-r--r-- | src/common/compress_zlib.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/common/compress_zlib.c b/src/common/compress_zlib.c index e1a68c2aa1..50bdf9ece1 100644 --- a/src/common/compress_zlib.c +++ b/src/common/compress_zlib.c @@ -50,6 +50,18 @@ static size_t tor_zlib_state_size_precalc(int inflate, /** Total number of bytes allocated for zlib state */ static size_t total_zlib_allocation = 0; +/** Given <b>level</b> return the memory level. */ +static int +memory_level(compression_level_t level) +{ + switch (level) { + default: + case HIGH_COMPRESSION: return 8; + case MEDIUM_COMPRESSION: return 7; + case LOW_COMPRESSION: return 6; + } +} + /** Return the 'bits' value to tell zlib to use <b>method</b>.*/ static inline int method_bits(compress_method_t method, compression_level_t level) @@ -120,7 +132,7 @@ tor_zlib_compress(char **out, size_t *out_len, if (deflateInit2(stream, Z_BEST_COMPRESSION, Z_DEFLATED, method_bits(method, HIGH_COMPRESSION), - tor_compress_memory_level(HIGH_COMPRESSION), + memory_level(HIGH_COMPRESSION), Z_DEFAULT_STRATEGY) != Z_OK) { //LCOV_EXCL_START -- we can only provoke failure by giving junk arguments. log_warn(LD_GENERAL, "Error from deflateInit2: %s", @@ -413,7 +425,7 @@ tor_zlib_compress_new(int compress, out->stream.opaque = NULL; out->compress = compress; bits = method_bits(method, compression_level); - memlevel = tor_compress_memory_level(compression_level); + memlevel = memory_level(compression_level); if (compress) { if (deflateInit2(&out->stream, Z_BEST_COMPRESSION, Z_DEFLATED, bits, memlevel, |