summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Compression.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-04-05 21:26:44 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-04-05 21:26:44 +0000
commita505f2479e98e50999376e572f905d93428bb93d (patch)
tree331b40d708769ec288d04a00cba09e82a1b8e8c4 /llvm/lib/Support/Compression.cpp
parentc12813576c58dadedec2ff722c40e5ff9dd20b84 (diff)
downloadbcm5719-llvm-a505f2479e98e50999376e572f905d93428bb93d.tar.gz
bcm5719-llvm-a505f2479e98e50999376e572f905d93428bb93d.zip
Simplify compression API by decompressing into a SmallVector rather than a MemoryBuffer
This avoids an extra copy during decompression and avoids the use of MemoryBuffer which is a weirdly esoteric device that includes unrelated concepts like "file name" (its rather generic name is a bit misleading). Similar refactoring of zlib::compress coming up. llvm-svn: 205676
Diffstat (limited to 'llvm/lib/Support/Compression.cpp')
-rw-r--r--llvm/lib/Support/Compression.cpp17
1 files changed, 6 insertions, 11 deletions
diff --git a/llvm/lib/Support/Compression.cpp b/llvm/lib/Support/Compression.cpp
index 5e5336144ab..329a402a070 100644
--- a/llvm/lib/Support/Compression.cpp
+++ b/llvm/lib/Support/Compression.cpp
@@ -65,18 +65,13 @@ zlib::Status zlib::compress(StringRef InputBuffer,
}
zlib::Status zlib::uncompress(StringRef InputBuffer,
- std::unique_ptr<MemoryBuffer> &UncompressedBuffer,
+ SmallVectorImpl<char> &UncompressedBuffer,
size_t UncompressedSize) {
- std::unique_ptr<char[]> TmpBuffer(new char[UncompressedSize]);
- Status Res = encodeZlibReturnValue(
- ::uncompress((Bytef *)TmpBuffer.get(), (uLongf *)&UncompressedSize,
- (const Bytef *)InputBuffer.data(), InputBuffer.size()));
- if (Res == StatusOK) {
- UncompressedBuffer.reset(MemoryBuffer::getMemBufferCopy(
- StringRef(TmpBuffer.get(), UncompressedSize)));
- // Tell MSan that memory initialized by zlib is valid.
- __msan_unpoison(UncompressedBuffer->getBufferStart(), UncompressedSize);
- }
+ UncompressedBuffer.resize(UncompressedSize);
+ Status Res = encodeZlibReturnValue(::uncompress(
+ (Bytef *)UncompressedBuffer.data(), (uLongf *)&UncompressedSize,
+ (const Bytef *)InputBuffer.data(), InputBuffer.size()));
+ UncompressedBuffer.resize(UncompressedSize);
return Res;
}
OpenPOWER on IntegriCloud