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

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed May 17 10:19:24 PDT 2017


LGTM

George Rimar via Phabricator <reviews at reviews.llvm.org> writes:

> grimar updated this revision to Diff 99284.
> grimar added a comment.
>
> - Fix comment.
>
>
> https://reviews.llvm.org/D33200
>
> Files:
>   include/llvm/Object/Decompressor.h
>   lib/DebugInfo/DWARF/DWARFContext.cpp
>   lib/Object/Decompressor.cpp
>   tools/llvm-dwp/llvm-dwp.cpp
>
>
> Index: tools/llvm-dwp/llvm-dwp.cpp
> ===================================================================
> --- tools/llvm-dwp/llvm-dwp.cpp
> +++ tools/llvm-dwp/llvm-dwp.cpp
> @@ -373,7 +373,7 @@
>      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"
> Index: lib/Object/Decompressor.cpp
> ===================================================================
> --- lib/Object/Decompressor.cpp
> +++ lib/Object/Decompressor.cpp
> @@ -88,11 +88,6 @@
>    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: lib/DebugInfo/DWARF/DWARFContext.cpp
> ===================================================================
> --- lib/DebugInfo/DWARF/DWARFContext.cpp
> +++ lib/DebugInfo/DWARF/DWARFContext.cpp
> @@ -979,7 +979,7 @@
>      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: include/llvm/Object/Decompressor.h
> ===================================================================
> --- include/llvm/Object/Decompressor.h
> +++ include/llvm/Object/Decompressor.h
> @@ -29,8 +29,11 @@
>                                         bool IsLE, bool Is64Bit);
>  
>    /// @brief Resize the buffer and uncompress section data into it.
> -  /// @param Out         Destination buffer.
> -  Error decompress(SmallString<32> &Out);
> +  /// @param Out      Destination buffer.
> +  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: tools/llvm-dwp/llvm-dwp.cpp
> ===================================================================
> --- tools/llvm-dwp/llvm-dwp.cpp
> +++ tools/llvm-dwp/llvm-dwp.cpp
> @@ -373,7 +373,7 @@
>      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"
> Index: lib/Object/Decompressor.cpp
> ===================================================================
> --- lib/Object/Decompressor.cpp
> +++ lib/Object/Decompressor.cpp
> @@ -88,11 +88,6 @@
>    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: lib/DebugInfo/DWARF/DWARFContext.cpp
> ===================================================================
> --- lib/DebugInfo/DWARF/DWARFContext.cpp
> +++ lib/DebugInfo/DWARF/DWARFContext.cpp
> @@ -979,7 +979,7 @@
>      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: include/llvm/Object/Decompressor.h
> ===================================================================
> --- include/llvm/Object/Decompressor.h
> +++ include/llvm/Object/Decompressor.h
> @@ -29,8 +29,11 @@
>                                         bool IsLE, bool Is64Bit);
>  
>    /// @brief Resize the buffer and uncompress section data into it.
> -  /// @param Out         Destination buffer.
> -  Error decompress(SmallString<32> &Out);
> +  /// @param Out      Destination buffer.
> +  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.


More information about the llvm-commits mailing list