[lld] r284092 - Move a utility function to Strings.cpp.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 12 17:13:16 PDT 2016


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()};
+}
 }
 }
 




More information about the llvm-commits mailing list