[llvm] r303331 - [lib/Object] - Minor API update for llvm::Decompressor.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu May 18 01:00:02 PDT 2017


Author: grimar
Date: Thu May 18 03:00:01 2017
New Revision: 303331

URL: http://llvm.org/viewvc/llvm-project?rev=303331&view=rev
Log:
[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<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

Modified:
    llvm/trunk/include/llvm/Object/Decompressor.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/trunk/lib/Object/Decompressor.cpp
    llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp

Modified: llvm/trunk/include/llvm/Object/Decompressor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Decompressor.h?rev=303331&r1=303330&r2=303331&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Decompressor.h (original)
+++ llvm/trunk/include/llvm/Object/Decompressor.h Thu May 18 03:00:01 2017
@@ -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.

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=303331&r1=303330&r2=303331&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Thu May 18 03:00:01 2017
@@ -979,7 +979,7 @@ Error DWARFContextInMemory::maybeDecompr
     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));

Modified: llvm/trunk/lib/Object/Decompressor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Decompressor.cpp?rev=303331&r1=303330&r2=303331&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Decompressor.cpp (original)
+++ llvm/trunk/lib/Object/Decompressor.cpp Thu May 18 03:00:01 2017
@@ -88,11 +88,6 @@ bool Decompressor::isCompressedELFSectio
   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);

Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=303331&r1=303330&r2=303331&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Thu May 18 03:00:01 2017
@@ -373,7 +373,7 @@ handleCompressedSection(std::deque<Small
     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"




More information about the llvm-commits mailing list