summaryrefslogtreecommitdiff
path: root/lib/Support/Compression.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-01-19 10:01:25 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-01-19 10:01:25 +0000
commitd8e91e46262bc44006913e6796843909f1ac7bcd (patch)
tree7d0c143d9b38190e0fa0180805389da22cd834c5 /lib/Support/Compression.cpp
parentb7eb8e35e481a74962664b63dfb09483b200209a (diff)
Notes
Diffstat (limited to 'lib/Support/Compression.cpp')
-rw-r--r--lib/Support/Compression.cpp28
1 files changed, 7 insertions, 21 deletions
diff --git a/lib/Support/Compression.cpp b/lib/Support/Compression.cpp
index c279d10f6c61..95261d4aad23 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
-