diff options
-rw-r--r-- | libcxxabi/src/demangle/StringViewExtras.h | 12 | ||||
-rw-r--r-- | llvm/include/llvm/Demangle/StringViewExtras.h | 12 |
2 files changed, 16 insertions, 8 deletions
diff --git a/libcxxabi/src/demangle/StringViewExtras.h b/libcxxabi/src/demangle/StringViewExtras.h index d430e67..0ad1f8c 100644 --- a/libcxxabi/src/demangle/StringViewExtras.h +++ b/libcxxabi/src/demangle/StringViewExtras.h @@ -21,12 +21,16 @@ DEMANGLE_NAMESPACE_BEGIN -inline bool starts_with(std::string_view self, char C) { - return !self.empty() && self.front() == C; +inline bool starts_with(std::string_view self, char C) noexcept { + return !self.empty() && *self.begin() == C; } -inline bool starts_with(std::string_view haystack, std::string_view needle) { - return haystack.substr(0, needle.size()) == needle; +inline bool starts_with(std::string_view haystack, + std::string_view needle) noexcept { + if (needle.size() > haystack.size()) + return false; + haystack.remove_suffix(haystack.size() - needle.size()); + return haystack == needle; } DEMANGLE_NAMESPACE_END diff --git a/llvm/include/llvm/Demangle/StringViewExtras.h b/llvm/include/llvm/Demangle/StringViewExtras.h index e4c2861..93940a5 100644 --- a/llvm/include/llvm/Demangle/StringViewExtras.h +++ b/llvm/include/llvm/Demangle/StringViewExtras.h @@ -21,12 +21,16 @@ DEMANGLE_NAMESPACE_BEGIN -inline bool starts_with(std::string_view self, char C) { - return !self.empty() && self.front() == C; +inline bool starts_with(std::string_view self, char C) noexcept { + return !self.empty() && *self.begin() == C; } -inline bool starts_with(std::string_view haystack, std::string_view needle) { - return haystack.substr(0, needle.size()) == needle; +inline bool starts_with(std::string_view haystack, + std::string_view needle) noexcept { + if (needle.size() > haystack.size()) + return false; + haystack.remove_suffix(haystack.size() - needle.size()); + return haystack == needle; } DEMANGLE_NAMESPACE_END |