X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Fcompression%2FZlib.cpp;h=8547a8164f3eb4bfa875b686b1389016a1d22dd4;hp=55034647c2f8b56f0a4340940681ec41e27779ed;hb=59cb2ab00419bffb627e89cb096e1288c2f37eeb;hpb=0c20289b724cf462078cf70d0ea1487f67b45fa8;ds=sidebyside diff --git a/folly/compression/Zlib.cpp b/folly/compression/Zlib.cpp index 55034647..8547a816 100644 --- a/folly/compression/Zlib.cpp +++ b/folly/compression/Zlib.cpp @@ -194,32 +194,28 @@ std::unique_ptr ZlibStreamCodec::createStream( return std::make_unique(options, level); } -static bool inBounds(int value, int low, int high) { - return (value >= low) && (value <= high); -} - -static int zlibConvertLevel(int level) { +ZlibStreamCodec::ZlibStreamCodec(Options options, int level) + : StreamCodec(getCodecType(options)) { switch (level) { case COMPRESSION_LEVEL_FASTEST: - return 1; + level = 1; + break; case COMPRESSION_LEVEL_DEFAULT: - return 6; + level = Z_DEFAULT_COMPRESSION; + break; case COMPRESSION_LEVEL_BEST: - return 9; + level = 9; + break; } - if (!inBounds(level, 0, 9)) { + auto inBounds = [](int value, int low, int high) { + return (value >= low) && (value <= high); + }; + + if (level != Z_DEFAULT_COMPRESSION && !inBounds(level, 0, 9)) { throw std::invalid_argument( to("ZlibStreamCodec: invalid level: ", level)); } - return level; -} - -ZlibStreamCodec::ZlibStreamCodec(Options options, int level) - : StreamCodec( - getCodecType(options), - zlibConvertLevel(level), - getCodecType(options) == CodecType::GZIP ? "gzip" : "zlib"), - level_(zlibConvertLevel(level)) { + level_ = level; options_ = options; // Although zlib allows a windowSize of 8..15, a value of 8 is not