[lld] r230770 - PECOFF: Use StringRef::find_first_of instead of a hand-written loop.
Rui Ueyama
ruiu at google.com
Fri Feb 27 10:06:41 PST 2015
Author: ruiu
Date: Fri Feb 27 12:06:41 2015
New Revision: 230770
URL: http://llvm.org/viewvc/llvm-project?rev=230770&view=rev
Log:
PECOFF: Use StringRef::find_first_of instead of a hand-written loop.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=230770&r1=230769&r2=230770&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Fri Feb 27 12:06:41 2015
@@ -1052,19 +1052,11 @@ StringRef FileCOFF::ArrayRefToString(Arr
array[2] == 0xBF) {
array = array.slice(3);
}
-
if (array.empty())
return "";
-
- // This is equivalent to strnlen, but we don't use the function because
- // it only exists in recent POSIX standards.
- size_t len = 0;
- size_t e = array.size();
- while (len < e && array[len] != '\0')
- ++len;
-
- std::string *contents =
- new (_alloc) std::string(reinterpret_cast<const char *>(&array[0]), len);
+ StringRef s((char *)array.data(), array.size());
+ s = s.substr(0, s.find_first_of('\0'));
+ std::string *contents = new (_alloc) std::string(s.data(), s.size());
return StringRef(*contents).trim();
}
More information about the llvm-commits
mailing list