X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FCompression.cpp;h=c32eb21343edddf0b30f9acebdfe1efae14370ae;hb=c5b413060c1775c134f934d38a766a0095284ed2;hp=b5ddb7002cade054282a19d5cf9905c09fcd59f6;hpb=ef7aefc53bf24214f489bf9e4100bcff45f7b12a;p=oota-llvm.git diff --git a/lib/Support/Compression.cpp b/lib/Support/Compression.cpp index b5ddb7002ca..c32eb21343e 100644 --- a/lib/Support/Compression.cpp +++ b/lib/Support/Compression.cpp @@ -12,12 +12,10 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Compression.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringRef.h" #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 #endif @@ -48,36 +46,26 @@ static zlib::Status encodeZlibReturnValue(int ReturnValue) { bool zlib::isAvailable() { return true; } zlib::Status zlib::compress(StringRef InputBuffer, - OwningPtr &CompressedBuffer, + SmallVectorImpl &CompressedBuffer, CompressionLevel Level) { unsigned long CompressedSize = ::compressBound(InputBuffer.size()); - OwningArrayPtr 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; } zlib::Status zlib::uncompress(StringRef InputBuffer, - OwningPtr &UncompressedBuffer, + SmallVectorImpl &UncompressedBuffer, size_t UncompressedSize) { - OwningArrayPtr 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; } @@ -88,12 +76,12 @@ uint32_t zlib::crc32(StringRef Buffer) { #else bool zlib::isAvailable() { return false; } zlib::Status zlib::compress(StringRef InputBuffer, - OwningPtr &CompressedBuffer, + SmallVectorImpl &CompressedBuffer, CompressionLevel Level) { return zlib::StatusUnsupported; } zlib::Status zlib::uncompress(StringRef InputBuffer, - OwningPtr &UncompressedBuffer, + SmallVectorImpl &UncompressedBuffer, size_t UncompressedSize) { return zlib::StatusUnsupported; }