[PATCH] D33200: [lib/Object] - Minor API update for llvm::Decompressor (simplify).
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon May 15 08:17:23 PDT 2017
This just inlines the method everywhere. If you want to be able to use
something like a std::string, why not just use a template:
template<class T>
Error Decompressor::resizeAnddecompress(T &Out) {
Out.resize(DecompressedSize);
return decompress({Out.data(), (size_t)DecompressedSize});
}
Cheers,
Rafael
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
> grimar created this revision.
>
> I revisited Decompressor API (issue with it was triggered during https://reviews.llvm.org/D32865 review)
> and found it is probably provides more then we really need.
>
> Issue was abount net 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. I think we can remove that
> method at all and simplify API a bit.
>
>
> 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,6 +373,7 @@
> return createError(Name, Dec.takeError());
>
> UncompressedSections.emplace_back();
> + UncompressedSections.back().resize(Dec->getDecompressedSize());
> if (Error E = Dec->decompress(UncompressedSections.back()))
> return createError(Name, std::move(E));
>
> 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,6 +979,7 @@
> return Decompressor.takeError();
>
> SmallString<32> Out;
> + Out.resize(Decompressor->getDecompressedSize());
> if (auto Err = Decompressor->decompress(Out))
> return Err;
>
> Index: include/llvm/Object/Decompressor.h
> ===================================================================
> --- include/llvm/Object/Decompressor.h
> +++ include/llvm/Object/Decompressor.h
> @@ -28,10 +28,6 @@
> static Expected<Decompressor> create(StringRef Name, StringRef Data,
> bool IsLE, bool Is64Bit);
>
> - /// @brief Resize the buffer and uncompress section data into it.
> - /// @param Out Destination buffer.
> - Error decompress(SmallString<32> &Out);
> -
> /// @brief Uncompress section data to raw buffer provided.
> /// @param Buffer Destination buffer.
> Error decompress(MutableArrayRef<char> Buffer);
>
>
> Index: tools/llvm-dwp/llvm-dwp.cpp
> ===================================================================
> --- tools/llvm-dwp/llvm-dwp.cpp
> +++ tools/llvm-dwp/llvm-dwp.cpp
> @@ -373,6 +373,7 @@
> return createError(Name, Dec.takeError());
>
> UncompressedSections.emplace_back();
> + UncompressedSections.back().resize(Dec->getDecompressedSize());
> if (Error E = Dec->decompress(UncompressedSections.back()))
> return createError(Name, std::move(E));
>
> 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,6 +979,7 @@
> return Decompressor.takeError();
>
> SmallString<32> Out;
> + Out.resize(Decompressor->getDecompressedSize());
> if (auto Err = Decompressor->decompress(Out))
> return Err;
>
> Index: include/llvm/Object/Decompressor.h
> ===================================================================
> --- include/llvm/Object/Decompressor.h
> +++ include/llvm/Object/Decompressor.h
> @@ -28,10 +28,6 @@
> static Expected<Decompressor> create(StringRef Name, StringRef Data,
> bool IsLE, bool Is64Bit);
>
> - /// @brief Resize the buffer and uncompress section data into it.
> - /// @param Out Destination buffer.
> - Error decompress(SmallString<32> &Out);
> -
> /// @brief Uncompress section data to raw buffer provided.
> /// @param Buffer Destination buffer.
> Error decompress(MutableArrayRef<char> Buffer);
More information about the llvm-commits
mailing list