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_lzma.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_lzma.c')
-rw-r--r-- | src/common/compress_lzma.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/common/compress_lzma.c b/src/common/compress_lzma.c index f2952cccda..ae0327f581 100644 --- a/src/common/compress_lzma.c +++ b/src/common/compress_lzma.c @@ -26,6 +26,18 @@ static size_t total_lzma_allocation = 0; #ifdef HAVE_LZMA +/** Given <b>level</b> return the memory level. */ +static int +memory_level(compression_level_t level) +{ + switch (level) { + default: + case HIGH_COMPRESSION: return 9; + case MEDIUM_COMPRESSION: return 6; + case LOW_COMPRESSION: return 3; + } +} + /** Convert a given <b>error</b> to a human readable error string. */ static const char * lzma_error_str(lzma_ret error) @@ -124,7 +136,7 @@ tor_lzma_compress(char **out, size_t *out_len, stream.avail_in = in_len; lzma_lzma_preset(&stream_options, - tor_compress_memory_level(HIGH_COMPRESSION)); + memory_level(HIGH_COMPRESSION)); retval = lzma_alone_encoder(&stream, &stream_options); @@ -432,7 +444,7 @@ tor_lzma_compress_new(int compress, if (compress) { lzma_lzma_preset(&stream_options, - tor_compress_memory_level(compression_level)); + memory_level(compression_level)); retval = lzma_alone_encoder(&result->stream, &stream_options); |