[llvm] r188380 - Expose CRC-32 implementation from zlib
Alexey Samsonov
samsonov at google.com
Wed Aug 14 09:03:30 PDT 2013
Author: samsonov
Date: Wed Aug 14 11:03:29 2013
New Revision: 188380
URL: http://llvm.org/viewvc/llvm-project?rev=188380&view=rev
Log:
Expose CRC-32 implementation from zlib
Modified:
llvm/trunk/include/llvm/Support/Compression.h
llvm/trunk/lib/Support/Compression.cpp
llvm/trunk/unittests/Support/CompressionTest.cpp
Modified: llvm/trunk/include/llvm/Support/Compression.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compression.h?rev=188380&r1=188379&r2=188380&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Compression.h (original)
+++ llvm/trunk/include/llvm/Support/Compression.h Wed Aug 14 11:03:29 2013
@@ -50,6 +50,8 @@ Status uncompress(StringRef InputBuffer,
OwningPtr<MemoryBuffer> &UncompressedBuffer,
size_t UncompressedSize);
+uint32_t crc32(StringRef Buffer);
+
} // End of namespace zlib
} // End of namespace llvm
Modified: llvm/trunk/lib/Support/Compression.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Compression.cpp?rev=188380&r1=188379&r2=188380&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Compression.cpp (original)
+++ llvm/trunk/lib/Support/Compression.cpp Wed Aug 14 11:03:29 2013
@@ -81,6 +81,10 @@ zlib::Status zlib::uncompress(StringRef
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
size_t UncompressedSize) {
return zlib::StatusUnsupported;
}
+uint32_t zlib::crc32(StringRef Buffer) {
+ llvm_unreachable("zlib::crc32 is unavailable");
+}
#endif
Modified: llvm/trunk/unittests/Support/CompressionTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CompressionTest.cpp?rev=188380&r1=188379&r2=188380&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/CompressionTest.cpp (original)
+++ llvm/trunk/unittests/Support/CompressionTest.cpp Wed Aug 14 11:03:29 2013
@@ -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
}
More information about the llvm-commits
mailing list