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
This commit is contained in:
David Blaikie
2014-04-05 21:53:04 +00:00
parent b206103abc
commit b4074c010b
4 changed files with 23 additions and 33 deletions

View File

@ -237,23 +237,23 @@ const SmallVectorImpl<char> &MCCompressedFragment::getCompressedContents() const
assert(getParent()->size() == 1 &&
"Only compress sections containing a single fragment");
if (CompressedContents.empty()) {
std::unique_ptr<MemoryBuffer> CompressedSection;
// FIXME: could be more efficient if we let zlib::compress append to a
// buffer rather than always from the start.
zlib::Status Success =
zlib::compress(StringRef(getContents().data(), getContents().size()),
CompressedSection);
CompressedContents);
(void)Success;
assert(Success == zlib::StatusOK);
CompressedContents.push_back('Z');
CompressedContents.push_back('L');
CompressedContents.push_back('I');
CompressedContents.push_back('B');
static const StringRef Magic = "ZLIB";
uint64_t Size = getContents().size();
if (sys::IsLittleEndianHost)
Size = sys::SwapByteOrder(Size);
CompressedContents.append(reinterpret_cast<char *>(&Size),
reinterpret_cast<char *>(&Size + 1));
CompressedContents.append(CompressedSection->getBuffer().begin(),
CompressedSection->getBuffer().end());
CompressedContents.insert(CompressedContents.begin(),
Magic.size() + sizeof(Size));
std::copy(Magic.begin(), Magic.end(), CompressedContents.begin());
std::copy(reinterpret_cast<char *>(&Size),
reinterpret_cast<char *>(&Size + 1),
CompressedContents.begin() + Magic.size());
}
return CompressedContents;
}