diff options
Diffstat (limited to 'lib/Support/Compression.cpp')
| -rw-r--r-- | lib/Support/Compression.cpp | 28 | 
1 files changed, 7 insertions, 21 deletions
diff --git a/lib/Support/Compression.cpp b/lib/Support/Compression.cpp index c279d10f6c614..95261d4aad239 100644 --- a/lib/Support/Compression.cpp +++ b/lib/Support/Compression.cpp @@ -29,16 +29,6 @@ static Error createError(StringRef Err) {    return make_error<StringError>(Err, inconvertibleErrorCode());  } -static int encodeZlibCompressionLevel(zlib::CompressionLevel Level) { -  switch (Level) { -    case zlib::NoCompression: return 0; -    case zlib::BestSpeedCompression: return 1; -    case zlib::DefaultCompression: return Z_DEFAULT_COMPRESSION; -    case zlib::BestSizeCompression: return 9; -  } -  llvm_unreachable("Invalid zlib::CompressionLevel!"); -} -  static StringRef convertZlibCodeToString(int Code) {    switch (Code) {    case Z_MEM_ERROR: @@ -58,18 +48,16 @@ static StringRef convertZlibCodeToString(int Code) {  bool zlib::isAvailable() { return true; }  Error zlib::compress(StringRef InputBuffer, -                     SmallVectorImpl<char> &CompressedBuffer, -                     CompressionLevel Level) { +                     SmallVectorImpl<char> &CompressedBuffer, int Level) {    unsigned long CompressedSize = ::compressBound(InputBuffer.size()); -  CompressedBuffer.resize(CompressedSize); -  int CLevel = encodeZlibCompressionLevel(Level); -  int Res = ::compress2((Bytef *)CompressedBuffer.data(), &CompressedSize, -                        (const Bytef *)InputBuffer.data(), InputBuffer.size(), -                        CLevel); +  CompressedBuffer.reserve(CompressedSize); +  int Res = +      ::compress2((Bytef *)CompressedBuffer.data(), &CompressedSize, +                  (const Bytef *)InputBuffer.data(), InputBuffer.size(), Level);    // Tell MemorySanitizer that zlib output buffer is fully initialized.    // This avoids a false report when running LLVM with uninstrumented ZLib.    __msan_unpoison(CompressedBuffer.data(), CompressedSize); -  CompressedBuffer.resize(CompressedSize); +  CompressedBuffer.set_size(CompressedSize);    return Res ? createError(convertZlibCodeToString(Res)) : Error::success();  } @@ -101,8 +89,7 @@ uint32_t zlib::crc32(StringRef Buffer) {  #else  bool zlib::isAvailable() { return false; }  Error zlib::compress(StringRef InputBuffer, -                     SmallVectorImpl<char> &CompressedBuffer, -                     CompressionLevel Level) { +                     SmallVectorImpl<char> &CompressedBuffer, int Level) {    llvm_unreachable("zlib::compress is unavailable");  }  Error zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer, @@ -118,4 +105,3 @@ uint32_t zlib::crc32(StringRef Buffer) {    llvm_unreachable("zlib::crc32 is unavailable");  }  #endif -  | 
