mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205676 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user