summaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-04-05 21:53:04 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-04-05 21:53:04 +0000
commitb4074c010bc3d6c9a7323fabf68578b7b900a8a5 (patch)
treee64638f74295a4c9bf2dd066889c3e5bf1af04c8 /lib/Support
parentb206103abcf358453ac4ed8d4373f44f4c88e5c0 (diff)
downloadllvm-b4074c010bc3d6c9a7323fabf68578b7b900a8a5.tar.gz
llvm-b4074c010bc3d6c9a7323fabf68578b7b900a8a5.tar.bz2
llvm-b4074c010bc3d6c9a7323fabf68578b7b900a8a5.tar.xz
Simplify compression API by compressing into a SmallVector rather than a MemoryBuffer
This is the other half of r205676. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205677 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/Compression.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/lib/Support/Compression.cpp b/lib/Support/Compression.cpp
index 329a402a07..c32eb21343 100644
--- a/lib/Support/Compression.cpp
+++ b/lib/Support/Compression.cpp
@@ -16,7 +16,6 @@
#include "llvm/Config/config.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/MemoryBuffer.h"
#if LLVM_ENABLE_ZLIB == 1 && HAVE_ZLIB_H
#include <zlib.h>
#endif
@@ -47,20 +46,15 @@ static zlib::Status encodeZlibReturnValue(int ReturnValue) {
bool zlib::isAvailable() { return true; }
zlib::Status zlib::compress(StringRef InputBuffer,
- std::unique_ptr<MemoryBuffer> &CompressedBuffer,
+ SmallVectorImpl<char> &CompressedBuffer,
CompressionLevel Level) {
unsigned long CompressedSize = ::compressBound(InputBuffer.size());
- std::unique_ptr<char[]> TmpBuffer(new char[CompressedSize]);
+ CompressedBuffer.resize(CompressedSize);
int CLevel = encodeZlibCompressionLevel(Level);
Status Res = encodeZlibReturnValue(::compress2(
- (Bytef *)TmpBuffer.get(), &CompressedSize,
+ (Bytef *)CompressedBuffer.data(), &CompressedSize,
(const Bytef *)InputBuffer.data(), InputBuffer.size(), CLevel));
- if (Res == StatusOK) {
- CompressedBuffer.reset(MemoryBuffer::getMemBufferCopy(
- StringRef(TmpBuffer.get(), CompressedSize)));
- // Tell MSan that memory initialized by zlib is valid.
- __msan_unpoison(CompressedBuffer->getBufferStart(), CompressedSize);
- }
+ CompressedBuffer.resize(CompressedSize);
return Res;
}
@@ -82,12 +76,12 @@ uint32_t zlib::crc32(StringRef Buffer) {
#else
bool zlib::isAvailable() { return false; }
zlib::Status zlib::compress(StringRef InputBuffer,
- std::unique_ptr<MemoryBuffer> &CompressedBuffer,
+ SmallVectorImpl<char> &CompressedBuffer,
CompressionLevel Level) {
return zlib::StatusUnsupported;
}
zlib::Status zlib::uncompress(StringRef InputBuffer,
- std::unique_ptr<MemoryBuffer> &UncompressedBuffer,
+ SmallVectorImpl<char> &UncompressedBuffer,
size_t UncompressedSize) {
return zlib::StatusUnsupported;
}