diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-03-21 16:42:35 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-03-21 16:42:35 +0000 |
commit | 7f58c41dbad3584c8dc50cd2d1e82632b7943fd9 (patch) | |
tree | 5f965445a4ee5227b34e7602ccc36675a2ec99e7 | |
parent | 65025aa89d573f4bb9109b1fe3837f1e02affbfb (diff) | |
download | bcm5719-llvm-7f58c41dbad3584c8dc50cd2d1e82632b7943fd9.tar.gz bcm5719-llvm-7f58c41dbad3584c8dc50cd2d1e82632b7943fd9.zip |
StringRef: Just forward StringRef::find to libc's memchr.
Modern libc's have an SSE version of memchr which is a lot faster than our
hand-rolled version. In the past I was reluctant to use it because Darwin's
memchr used a naive ridiculously slow implementation, but that has been fixed
some versions ago.
Should have zero functional impact.
llvm-svn: 232898
-rw-r--r-- | llvm/include/llvm/ADT/StringRef.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h index 6111c42da9d..95660a49f1f 100644 --- a/llvm/include/llvm/ADT/StringRef.h +++ b/llvm/include/llvm/ADT/StringRef.h @@ -238,9 +238,12 @@ namespace llvm { /// \returns The index of the first occurrence of \p C, or npos if not /// found. size_t find(char C, size_t From = 0) const { - for (size_t i = std::min(From, Length), e = Length; i != e; ++i) - if (Data[i] == C) - return i; + size_t FindBegin = std::min(From, Length); + if (FindBegin < Length) { // Avoid calling memchr with nullptr. + // Just forward to memchr, which is faster than a hand-rolled loop. + if (const void *P = ::memchr(Data + FindBegin, C, Length - FindBegin)) + return static_cast<const char *>(P) - Data; + } return npos; } |