<div dir="ltr">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.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 17, 2016 at 10:22 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So, we need this because parts of the code use ArrayRef<uint8_t> and<br>
part use StringRef. I wonder if the semantic purity of using<br>
ArrayRef<uint8_t> is worth it.<br>
<br>
Any thoughts on just using StringRef everywhere?<br>
<br>
Cheers,<br>
Rafael<br>
<br>
<br>
On 12 October 2016 at 20:13, Rui Ueyama via llvm-commits<br>
<div class="HOEnZb"><div class="h5"><<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
> Author: ruiu<br>
> Date: Wed Oct 12 19:13:15 2016<br>
> New Revision: 284092<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=284092&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=284092&view=rev</a><br>
> Log:<br>
> Move a utility function to Strings.cpp.<br>
><br>
> So that we can use the function from anywhere.<br>
><br>
> Modified:<br>
>     lld/trunk/ELF/InputSection.cpp<br>
>     lld/trunk/ELF/OutputSections.<wbr>cpp<br>
>     lld/trunk/ELF/Strings.h<br>
><br>
> Modified: lld/trunk/ELF/InputSection.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=284092&r1=284091&r2=284092&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>InputSection.cpp?rev=284092&<wbr>r1=284091&r2=284092&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/ELF/InputSection.cpp (original)<br>
> +++ lld/trunk/ELF/InputSection.cpp Wed Oct 12 19:13:15 2016<br>
> @@ -160,8 +160,8 @@ template <class ELFT> void InputSectionB<br>
><br>
>    // Uncompress Buf.<br>
>    UncompressedData.reset(new uint8_t[Size]);<br>
> -  if (zlib::uncompress(StringRef((<wbr>const char *)Buf.data(), Buf.size()),<br>
> -                       (char *)UncompressedData.get(), Size) != zlib::StatusOK)<br>
> +  if (zlib::uncompress(toStringRef(<wbr>Buf), (char *)UncompressedData.get(),<br>
> +                       Size) != zlib::StatusOK)<br>
>      fatal(getName(this) + ": error while uncompressing section");<br>
>    Data = ArrayRef<uint8_t>(<wbr>UncompressedData.get(), Size);<br>
>  }<br>
><br>
> Modified: lld/trunk/ELF/OutputSections.<wbr>cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=284092&r1=284091&r2=284092&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>OutputSections.cpp?rev=284092&<wbr>r1=284091&r2=284092&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/ELF/OutputSections.<wbr>cpp (original)<br>
> +++ lld/trunk/ELF/OutputSections.<wbr>cpp Wed Oct 12 19:13:15 2016<br>
> @@ -1232,10 +1232,6 @@ template <class ELFT> void MergeOutputSe<br>
>    Builder.write(Buf);<br>
>  }<br>
><br>
> -static StringRef toStringRef(ArrayRef<uint8_t> A) {<br>
> -  return {(const char *)A.data(), A.size()};<br>
> -}<br>
> -<br>
>  template <class ELFT><br>
>  void MergeOutputSection<ELFT>::<wbr>addSection(InputSectionBase<<wbr>ELFT> *C) {<br>
>    auto *Sec = cast<MergeInputSection<ELFT>>(<wbr>C);<br>
> @@ -1694,7 +1690,7 @@ void BuildIdFastHash<ELFT>::<wbr>writeBuildId<br>
>    const endianness E = ELFT::TargetEndianness;<br>
><br>
>    // 64-bit xxhash<br>
> -  uint64_t Hash = xxHash64(StringRef((const char *)Buf.data(), Buf.size()));<br>
> +  uint64_t Hash = xxHash64(toStringRef(Buf));<br>
>    write64<E>(this->HashBuf, Hash);<br>
>  }<br>
><br>
><br>
> Modified: lld/trunk/ELF/Strings.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.h?rev=284092&r1=284091&r2=284092&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Strings.<wbr>h?rev=284092&r1=284091&r2=<wbr>284092&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- lld/trunk/ELF/Strings.h (original)<br>
> +++ lld/trunk/ELF/Strings.h Wed Oct 12 19:13:15 2016<br>
> @@ -11,6 +11,8 @@<br>
>  #define LLD_ELF_STRINGS_H<br>
><br>
>  #include "lld/Core/LLVM.h"<br>
> +#include "llvm/ADT/ArrayRef.h"<br>
> +#include "llvm/ADT/StringRef.h"<br>
>  #include "llvm/Support/Regex.h"<br>
>  #include <vector><br>
><br>
> @@ -27,6 +29,10 @@ StringRef unquote(StringRef S);<br>
>  // name or the system does not provide __cxa_demangle function,<br>
>  // it returns an unmodified string.<br>
>  std::string demangle(StringRef Name);<br>
> +<br>
> +inline StringRef toStringRef(ArrayRef<uint8_t> Arr) {<br>
> +  return {(const char *)Arr.data(), Arr.size()};<br>
> +}<br>
>  }<br>
>  }<br>
><br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>