]> granicus.if.org Git - llvm/commitdiff
[lib/Object] - Minor API update for llvm::Decompressor.
authorGeorge Rimar <grimar@accesssoftek.com>
Thu, 18 May 2017 08:00:01 +0000 (08:00 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Thu, 18 May 2017 08:00:01 +0000 (08:00 +0000)
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<char> &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
lib/DebugInfo/DWARF/DWARFContext.cpp
lib/Object/Decompressor.cpp
tools/llvm-dwp/llvm-dwp.cpp

index a11857d546aaeb64fc392b891039e215fdfddacf..5af1b41bbe28769aa77a29718c1e6c35977bd10d 100644 (file)
@@ -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 <class T> 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.
index 61e75a2b56ab8eb5a26a00566f8cffce12784aa2..3dc1ec5789e6fb616852f69f4bc335b3a3d80298 100644 (file)
@@ -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));
index 0be602b1fc1ab5beddce65a77c6280943847469a..89d199a3f3f6eb4ba988e0cdb4201e92b9a21c23 100644 (file)
@@ -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<char> Buffer) {
   size_t Size = Buffer.size();
   return zlib::uncompress(SectionData, Buffer.data(), Size);
index 0c4af7576608c9ae0030427c14524d0a4a482843..f8d00b3b5534f4517b7f0f036dd648482bbf5d7d 100644 (file)
@@ -373,7 +373,7 @@ handleCompressedSection(std::deque<SmallString<32>> &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"