Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 1090c4b

Browse files
committed
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338939 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a5b8d5a commit 1090c4b

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

include/llvm/Support/Compression.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ class StringRef;
2323

2424
namespace zlib {
2525

26-
enum CompressionLevel {
27-
NoCompression,
28-
DefaultCompression,
29-
BestSpeedCompression,
30-
BestSizeCompression
31-
};
26+
static constexpr int NoCompression = 0;
27+
static constexpr int BestSpeedCompression = 1;
28+
static constexpr int DefaultCompression = 6;
29+
static constexpr int BestSizeCompression = 9;
3230

3331
bool isAvailable();
3432

3533
Error compress(StringRef InputBuffer, SmallVectorImpl<char> &CompressedBuffer,
36-
CompressionLevel Level = DefaultCompression);
34+
int Level = DefaultCompression);
3735

3836
Error uncompress(StringRef InputBuffer, char *UncompressedBuffer,
3937
size_t &UncompressedSize);
@@ -49,4 +47,3 @@ uint32_t crc32(StringRef Buffer);
4947
} // End of namespace llvm
5048

5149
#endif
52-

lib/Support/Compression.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ static Error createError(StringRef Err) {
2929
return make_error<StringError>(Err, inconvertibleErrorCode());
3030
}
3131

32-
static int encodeZlibCompressionLevel(zlib::CompressionLevel Level) {
33-
switch (Level) {
34-
case zlib::NoCompression: return 0;
35-
case zlib::BestSpeedCompression: return 1;
36-
case zlib::DefaultCompression: return Z_DEFAULT_COMPRESSION;
37-
case zlib::BestSizeCompression: return 9;
38-
}
39-
llvm_unreachable("Invalid zlib::CompressionLevel!");
40-
}
41-
4232
static StringRef convertZlibCodeToString(int Code) {
4333
switch (Code) {
4434
case Z_MEM_ERROR:
@@ -58,14 +48,12 @@ static StringRef convertZlibCodeToString(int Code) {
5848
bool zlib::isAvailable() { return true; }
5949

6050
Error zlib::compress(StringRef InputBuffer,
61-
SmallVectorImpl<char> &CompressedBuffer,
62-
CompressionLevel Level) {
51+
SmallVectorImpl<char> &CompressedBuffer, int Level) {
6352
unsigned long CompressedSize = ::compressBound(InputBuffer.size());
6453
CompressedBuffer.reserve(CompressedSize);
65-
int CLevel = encodeZlibCompressionLevel(Level);
66-
int Res = ::compress2((Bytef *)CompressedBuffer.data(), &CompressedSize,
67-
(const Bytef *)InputBuffer.data(), InputBuffer.size(),
68-
CLevel);
54+
int Res =
55+
::compress2((Bytef *)CompressedBuffer.data(), &CompressedSize,
56+
(const Bytef *)InputBuffer.data(), InputBuffer.size(), Level);
6957
// Tell MemorySanitizer that zlib output buffer is fully initialized.
7058
// This avoids a false report when running LLVM with uninstrumented ZLib.
7159
__msan_unpoison(CompressedBuffer.data(), CompressedSize);
@@ -118,4 +106,3 @@ uint32_t zlib::crc32(StringRef Buffer) {
118106
llvm_unreachable("zlib::crc32 is unavailable");
119107
}
120108
#endif
121-

unittests/Support/CompressionTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace {
2424

2525
#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ
2626

27-
void TestZlibCompression(StringRef Input, zlib::CompressionLevel Level) {
27+
void TestZlibCompression(StringRef Input, int Level) {
2828
SmallString<32> Compressed;
2929
SmallString<32> Uncompressed;
3030

0 commit comments

Comments
 (0)