summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2018-08-04 00:13:13 +0000
committerRui Ueyama <ruiu@google.com>2018-08-04 00:13:13 +0000
commit2c97adc1a7d601f416898f8370dce484d16705db (patch)
tree868da29e281b0cff281b56a45272e550a67a3b0b
parent47e2b6b29eae57267b5c966eb7d02dc8eae0caaf (diff)
downloadbcm5719-llvm-2c97adc1a7d601f416898f8370dce484d16705db.tar.gz
bcm5719-llvm-2c97adc1a7d601f416898f8370dce484d16705db.zip
Use the same constants as zlib to represent compression level.
This change allows users pass compression level that was not listed in the enum. Also, I think using different values than zlib's compression levels was just confusing. Differential Revision: https://reviews.llvm.org/D50196 llvm-svn: 338939
-rw-r--r--llvm/include/llvm/Support/Compression.h13
-rw-r--r--llvm/lib/Support/Compression.cpp21
-rw-r--r--llvm/unittests/Support/CompressionTest.cpp2
3 files changed, 10 insertions, 26 deletions
diff --git a/llvm/include/llvm/Support/Compression.h b/llvm/include/llvm/Support/Compression.h
index 2d191abe4b1..f7258f4bf8f 100644
--- a/llvm/include/llvm/Support/Compression.h
+++ b/llvm/include/llvm/Support/Compression.h
@@ -23,17 +23,15 @@ class StringRef;
namespace zlib {
-enum CompressionLevel {
- NoCompression,
- DefaultCompression,
- BestSpeedCompression,
- BestSizeCompression
-};
+static constexpr int NoCompression = 0;
+static constexpr int BestSpeedCompression = 1;
+static constexpr int DefaultCompression = 6;
+static constexpr int BestSizeCompression = 9;
bool isAvailable();
Error compress(StringRef InputBuffer, SmallVectorImpl<char> &CompressedBuffer,
- CompressionLevel Level = DefaultCompression);
+ int Level = DefaultCompression);
Error uncompress(StringRef InputBuffer, char *UncompressedBuffer,
size_t &UncompressedSize);
@@ -49,4 +47,3 @@ uint32_t crc32(StringRef Buffer);
} // End of namespace llvm
#endif
-
diff --git a/llvm/lib/Support/Compression.cpp b/llvm/lib/Support/Compression.cpp
index 05bd7b58e08..2217740e2ea 100644
--- a/llvm/lib/Support/Compression.cpp
+++ b/llvm/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,14 +48,12 @@ 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.reserve(CompressedSize);
- int CLevel = encodeZlibCompressionLevel(Level);
- int Res = ::compress2((Bytef *)CompressedBuffer.data(), &CompressedSize,
- (const Bytef *)InputBuffer.data(), InputBuffer.size(),
- CLevel);
+ 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);
@@ -118,4 +106,3 @@ uint32_t zlib::crc32(StringRef Buffer) {
llvm_unreachable("zlib::crc32 is unavailable");
}
#endif
-
diff --git a/llvm/unittests/Support/CompressionTest.cpp b/llvm/unittests/Support/CompressionTest.cpp
index 505714bd2da..e9f36c5eebd 100644
--- a/llvm/unittests/Support/CompressionTest.cpp
+++ b/llvm/unittests/Support/CompressionTest.cpp
@@ -24,7 +24,7 @@ namespace {
#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ
-void TestZlibCompression(StringRef Input, zlib::CompressionLevel Level) {
+void TestZlibCompression(StringRef Input, int Level) {
SmallString<32> Compressed;
SmallString<32> Uncompressed;
OpenPOWER on IntegriCloud