[lld] r284092 - Move a utility function to Strings.cpp.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 17 10:28:53 PDT 2016
It's sometimes tedious indeed, but I think I still like ArrayRef<uint8_t>
because it works as a hint to human that it contains a binary blob instead
of an ASCII (or UTF-8) string.
On Mon, Oct 17, 2016 at 10:22 AM, Rafael EspĂndola <
rafael.espindola at gmail.com> wrote:
> So, we need this because parts of the code use ArrayRef<uint8_t> and
> part use StringRef. I wonder if the semantic purity of using
> ArrayRef<uint8_t> is worth it.
>
> Any thoughts on just using StringRef everywhere?
>
> Cheers,
> Rafael
>
>
> On 12 October 2016 at 20:13, Rui Ueyama via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
> > Author: ruiu
> > Date: Wed Oct 12 19:13:15 2016
> > New Revision: 284092
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=284092&view=rev
> > Log:
> > Move a utility function to Strings.cpp.
> >
> > So that we can use the function from anywhere.
> >
> > Modified:
> > lld/trunk/ELF/InputSection.cpp
> > lld/trunk/ELF/OutputSections.cpp
> > lld/trunk/ELF/Strings.h
> >
> > Modified: lld/trunk/ELF/InputSection.cpp
> > URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
> InputSection.cpp?rev=284092&r1=284091&r2=284092&view=diff
> > ============================================================
> ==================
> > --- lld/trunk/ELF/InputSection.cpp (original)
> > +++ lld/trunk/ELF/InputSection.cpp Wed Oct 12 19:13:15 2016
> > @@ -160,8 +160,8 @@ template <class ELFT> void InputSectionB
> >
> > // Uncompress Buf.
> > UncompressedData.reset(new uint8_t[Size]);
> > - if (zlib::uncompress(StringRef((const char *)Buf.data(), Buf.size()),
> > - (char *)UncompressedData.get(), Size) !=
> zlib::StatusOK)
> > + if (zlib::uncompress(toStringRef(Buf), (char
> *)UncompressedData.get(),
> > + Size) != zlib::StatusOK)
> > fatal(getName(this) + ": error while uncompressing section");
> > Data = ArrayRef<uint8_t>(UncompressedData.get(), Size);
> > }
> >
> > Modified: lld/trunk/ELF/OutputSections.cpp
> > URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
> OutputSections.cpp?rev=284092&r1=284091&r2=284092&view=diff
> > ============================================================
> ==================
> > --- lld/trunk/ELF/OutputSections.cpp (original)
> > +++ lld/trunk/ELF/OutputSections.cpp Wed Oct 12 19:13:15 2016
> > @@ -1232,10 +1232,6 @@ template <class ELFT> void MergeOutputSe
> > Builder.write(Buf);
> > }
> >
> > -static StringRef toStringRef(ArrayRef<uint8_t> A) {
> > - return {(const char *)A.data(), A.size()};
> > -}
> > -
> > template <class ELFT>
> > void MergeOutputSection<ELFT>::addSection(InputSectionBase<ELFT> *C) {
> > auto *Sec = cast<MergeInputSection<ELFT>>(C);
> > @@ -1694,7 +1690,7 @@ void BuildIdFastHash<ELFT>::writeBuildId
> > const endianness E = ELFT::TargetEndianness;
> >
> > // 64-bit xxhash
> > - uint64_t Hash = xxHash64(StringRef((const char *)Buf.data(),
> Buf.size()));
> > + uint64_t Hash = xxHash64(toStringRef(Buf));
> > write64<E>(this->HashBuf, Hash);
> > }
> >
> >
> > Modified: lld/trunk/ELF/Strings.h
> > URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.
> h?rev=284092&r1=284091&r2=284092&view=diff
> > ============================================================
> ==================
> > --- lld/trunk/ELF/Strings.h (original)
> > +++ lld/trunk/ELF/Strings.h Wed Oct 12 19:13:15 2016
> > @@ -11,6 +11,8 @@
> > #define LLD_ELF_STRINGS_H
> >
> > #include "lld/Core/LLVM.h"
> > +#include "llvm/ADT/ArrayRef.h"
> > +#include "llvm/ADT/StringRef.h"
> > #include "llvm/Support/Regex.h"
> > #include <vector>
> >
> > @@ -27,6 +29,10 @@ StringRef unquote(StringRef S);
> > // name or the system does not provide __cxa_demangle function,
> > // it returns an unmodified string.
> > std::string demangle(StringRef Name);
> > +
> > +inline StringRef toStringRef(ArrayRef<uint8_t> Arr) {
> > + return {(const char *)Arr.data(), Arr.size()};
> > +}
> > }
> > }
> >
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161017/ed6ebd0c/attachment.html>
More information about the llvm-commits
mailing list