diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2023-01-15 20:58:09 +0100 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2023-01-15 21:20:55 +0100 |
commit | 2f851f26ead0ea68c110584674555562af07d9e1 (patch) | |
tree | b0ded47bb1067d45862589de9cb2452a8efd2d57 /llvm/lib/Support/StringRef.cpp | |
parent | 931d04be2fc8f3f0505b43e64297f75d526cb42a (diff) | |
download | llvm-2f851f26ead0ea68c110584674555562af07d9e1.zip llvm-2f851f26ead0ea68c110584674555562af07d9e1.tar.gz llvm-2f851f26ead0ea68c110584674555562af07d9e1.tar.bz2 |
[ADT] Forward some StringRef::find overloads to std::string_view
These are identical in terms of functionality and performance (checked
libc++ and libstdc++). We could do the same for rfind, but that actually
has a off-by one on its position argument.
StringRef::find(StringRef) seems to be quite a bit more optimized than
the standard library one, so leave it alone.
Diffstat (limited to 'llvm/lib/Support/StringRef.cpp')
-rw-r--r-- | llvm/lib/Support/StringRef.cpp | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp index f9fa511..fb93940 100644 --- a/llvm/lib/Support/StringRef.cpp +++ b/llvm/lib/Support/StringRef.cpp @@ -215,15 +215,7 @@ size_t StringRef::rfind_insensitive(char C, size_t From) const { /// \return - The index of the last occurrence of \arg Str, or npos if not /// found. size_t StringRef::rfind(StringRef Str) const { - size_t N = Str.size(); - if (N > Length) - return npos; - for (size_t i = Length - N + 1, e = 0; i != e;) { - --i; - if (substr(i, N).equals(Str)) - return i; - } - return npos; + return std::string_view(*this).rfind(Str); } size_t StringRef::rfind_insensitive(StringRef Str) const { @@ -257,10 +249,7 @@ StringRef::size_type StringRef::find_first_of(StringRef Chars, /// find_first_not_of - Find the first character in the string that is not /// \arg C or npos if not found. StringRef::size_type StringRef::find_first_not_of(char C, size_t From) const { - for (size_type i = std::min(From, Length), e = Length; i != e; ++i) - if (Data[i] != C) - return i; - return npos; + return std::string_view(*this).find_first_not_of(C, From); } /// find_first_not_of - Find the first character in the string that is not |