From 336421009326f8660cc3556c83b74bf63670e51b Mon Sep 17 00:00:00 2001 From: George Rimar Date: Thu, 18 May 2017 08:00:01 +0000 Subject: [PATCH] [lib/Object] - Minor API update for llvm::Decompressor. I revisited Decompressor API (issue with it was triggered during D32865 review) and found it is probably provides more then we really need. Issue was about next method's signature: Error decompress(SmallString<32> &Out); It is too strict. At first I wanted to change it to decompress(SmallVectorImpl &Out), but then found it is still not flexible because sticks to SmallVector. During reviews was suggested to use templating to simplify code. Patch do that. Differential revision: https://reviews.llvm.org/D33200 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303331 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/Decompressor.h | 5 ++++- lib/DebugInfo/DWARF/DWARFContext.cpp | 2 +- lib/Object/Decompressor.cpp | 5 ----- tools/llvm-dwp/llvm-dwp.cpp | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/llvm/Object/Decompressor.h b/include/llvm/Object/Decompressor.h index a11857d546a..5af1b41bbe2 100644 --- a/include/llvm/Object/Decompressor.h +++ b/include/llvm/Object/Decompressor.h @@ -30,7 +30,10 @@ public: /// @brief Resize the buffer and uncompress section data into it. /// @param Out Destination buffer. - Error decompress(SmallString<32> &Out); + template Error Decompressor::resizeAndDecompress(T &Out) { + Out.resize(DecompressedSize); + return decompress({Out.data(), (size_t)DecompressedSize}); + } /// @brief Uncompress section data to raw buffer provided. /// @param Buffer Destination buffer. diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index 61e75a2b56a..3dc1ec5789e 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -979,7 +979,7 @@ Error DWARFContextInMemory::maybeDecompress(const SectionRef &Sec, return Decompressor.takeError(); SmallString<32> Out; - if (auto Err = Decompressor->decompress(Out)) + if (auto Err = Decompressor->resizeAndDecompress(Out)) return Err; UncompressedSections.emplace_back(std::move(Out)); diff --git a/lib/Object/Decompressor.cpp b/lib/Object/Decompressor.cpp index 0be602b1fc1..89d199a3f3f 100644 --- a/lib/Object/Decompressor.cpp +++ b/lib/Object/Decompressor.cpp @@ -88,11 +88,6 @@ bool Decompressor::isCompressedELFSection(uint64_t Flags, StringRef Name) { return (Flags & ELF::SHF_COMPRESSED) || isGnuStyle(Name); } -Error Decompressor::decompress(SmallString<32> &Out) { - Out.resize(DecompressedSize); - return decompress({Out.data(), (size_t)DecompressedSize}); -} - Error Decompressor::decompress(MutableArrayRef Buffer) { size_t Size = Buffer.size(); return zlib::uncompress(SectionData, Buffer.data(), Size); diff --git a/tools/llvm-dwp/llvm-dwp.cpp b/tools/llvm-dwp/llvm-dwp.cpp index 0c4af757660..f8d00b3b553 100644 --- a/tools/llvm-dwp/llvm-dwp.cpp +++ b/tools/llvm-dwp/llvm-dwp.cpp @@ -373,7 +373,7 @@ handleCompressedSection(std::deque> &UncompressedSections, return createError(Name, Dec.takeError()); UncompressedSections.emplace_back(); - if (Error E = Dec->decompress(UncompressedSections.back())) + if (Error E = Dec->resizeAndDecompress(UncompressedSections.back())) return createError(Name, std::move(E)); Name = Name.substr(2); // Drop ".z" -- 2.50.1