From ef7aefc53bf24214f489bf9e4100bcff45f7b12a Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Wed, 14 Aug 2013 16:03:29 +0000 Subject: [PATCH] Expose CRC-32 implementation from zlib git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188380 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Compression.h | 2 ++ lib/Support/Compression.cpp | 7 +++++++ unittests/Support/CompressionTest.cpp | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/include/llvm/Support/Compression.h b/include/llvm/Support/Compression.h index 9b1142d035d..bef9146d07d 100644 --- a/include/llvm/Support/Compression.h +++ b/include/llvm/Support/Compression.h @@ -50,6 +50,8 @@ Status uncompress(StringRef InputBuffer, OwningPtr &UncompressedBuffer, size_t UncompressedSize); +uint32_t crc32(StringRef Buffer); + } // End of namespace zlib } // End of namespace llvm diff --git a/lib/Support/Compression.cpp b/lib/Support/Compression.cpp index fd8a8743ea1..b5ddb7002ca 100644 --- a/lib/Support/Compression.cpp +++ b/lib/Support/Compression.cpp @@ -81,6 +81,10 @@ zlib::Status zlib::uncompress(StringRef InputBuffer, return Res; } +uint32_t zlib::crc32(StringRef Buffer) { + return ::crc32(0, (const Bytef *)Buffer.data(), Buffer.size()); +} + #else bool zlib::isAvailable() { return false; } zlib::Status zlib::compress(StringRef InputBuffer, @@ -93,5 +97,8 @@ zlib::Status zlib::uncompress(StringRef InputBuffer, size_t UncompressedSize) { return zlib::StatusUnsupported; } +uint32_t zlib::crc32(StringRef Buffer) { + llvm_unreachable("zlib::crc32 is unavailable"); +} #endif diff --git a/unittests/Support/CompressionTest.cpp b/unittests/Support/CompressionTest.cpp index c8e2cd9f02b..c0a9adadb78 100644 --- a/unittests/Support/CompressionTest.cpp +++ b/unittests/Support/CompressionTest.cpp @@ -63,6 +63,12 @@ TEST(CompressionTest, Zlib) { TestZlibCompression(BinaryDataStr, zlib::DefaultCompression); } +TEST(CompressionTest, ZlibCRC32) { + EXPECT_EQ( + 0x414FA339U, + zlib::crc32(StringRef("The quick brown fox jumps over the lazy dog"))); +} + #endif } -- 2.34.1