[tor-commits] [tor/master] Add a "best compression" flag.

nickm at torproject.org nickm at torproject.org
Tue Apr 25 14:51:21 UTC 2017


commit 4b01b45ec1a2d561eab8bf7d8934857268e48701
Author: Nick Mathewson <nickm at torproject.org>
Date:   Tue Apr 25 09:54:02 2017 -0400

    Add a "best compression" flag.
---
 src/common/compress.c      | 6 +++---
 src/common/compress.h      | 4 ++--
 src/common/compress_lzma.c | 1 +
 src/common/compress_zlib.c | 4 +++-
 src/common/compress_zstd.c | 1 +
 5 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/common/compress.c b/src/common/compress.c
index 2729d9f..e8d11b9 100644
--- a/src/common/compress.c
+++ b/src/common/compress.c
@@ -208,8 +208,8 @@ tor_compress(char **out, size_t *out_len,
              compress_method_t method)
 {
   return tor_compress_impl(1, out, out_len, in, in_len, method,
-                           HIGH_COMPRESSION,
-                           1, LOG_WARN); // XXXX "best"?
+                           BEST_COMPRESSION,
+                           1, LOG_WARN);
 }
 
 /** Given zero or more zlib-compressed or gzip-compressed strings of
@@ -231,7 +231,7 @@ tor_uncompress(char **out, size_t *out_len,
                int protocol_warn_level)
 {
   return tor_compress_impl(0, out, out_len, in, in_len, method,
-                           HIGH_COMPRESSION,
+                           BEST_COMPRESSION,
                            complete_only, protocol_warn_level);
 }
 
diff --git a/src/common/compress.h b/src/common/compress.h
index 2d812e4..8be67df 100644
--- a/src/common/compress.h
+++ b/src/common/compress.h
@@ -26,11 +26,11 @@ typedef enum {
 
 /**
  * Enumeration to define tradeoffs between memory usage and compression level.
- * HIGH_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most
+ * BEST_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most
  * memory.
  **/
 typedef enum {
-  HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION
+  BEST_COMPRESSION, HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION
 } compression_level_t;
 
 int tor_compress(char **out, size_t *out_len,
diff --git a/src/common/compress_lzma.c b/src/common/compress_lzma.c
index 9c61d58..59b7df6 100644
--- a/src/common/compress_lzma.c
+++ b/src/common/compress_lzma.c
@@ -32,6 +32,7 @@ memory_level(compression_level_t level)
 {
   switch (level) {
     default:
+    case BEST_COMPRESSION:
     case HIGH_COMPRESSION: return 9;
     case MEDIUM_COMPRESSION: return 6;
     case LOW_COMPRESSION: return 3;
diff --git a/src/common/compress_zlib.c b/src/common/compress_zlib.c
index 37768ee..d8200d5 100644
--- a/src/common/compress_zlib.c
+++ b/src/common/compress_zlib.c
@@ -56,6 +56,7 @@ memory_level(compression_level_t level)
 {
   switch (level) {
     default:
+    case BEST_COMPRESSION: return 9;
     case HIGH_COMPRESSION: return 8;
     case MEDIUM_COMPRESSION: return 7;
     case LOW_COMPRESSION: return 6;
@@ -70,6 +71,7 @@ method_bits(compress_method_t method, compression_level_t level)
   const int flag = method == GZIP_METHOD ? 16 : 0;
   switch (level) {
     default:
+    case BEST_COMPRESSION:
     case HIGH_COMPRESSION: return flag + 15;
     case MEDIUM_COMPRESSION: return flag + 13;
     case LOW_COMPRESSION: return flag + 11;
@@ -162,7 +164,7 @@ tor_zlib_compress_new(int compress_,
   if (! compress_) {
     /* use this setting for decompression, since we might have the
      * max number of window bits */
-    compression_level = HIGH_COMPRESSION;
+    compression_level = BEST_COMPRESSION;
   }
 
   out = tor_malloc_zero(sizeof(tor_zlib_compress_state_t));
diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c
index 76f2991..58fa327 100644
--- a/src/common/compress_zstd.c
+++ b/src/common/compress_zstd.c
@@ -33,6 +33,7 @@ memory_level(compression_level_t level)
 {
   switch (level) {
     default:
+    case BEST_COMPRESSION:
     case HIGH_COMPRESSION: return 9;
     case MEDIUM_COMPRESSION: return 8;
     case LOW_COMPRESSION: return 7;





More information about the tor-commits mailing list