diff options
author | Nick Desaulniers <ndesaulniers@google.com> | 2023-05-25 14:29:12 -0700 |
---|---|---|
committer | Nick Desaulniers <ndesaulniers@google.com> | 2023-05-25 14:35:13 -0700 |
commit | ee740b714ba0de41f48a4fb4717fa9b9a22fedf2 (patch) | |
tree | 7db99bb32dc9d8ee27bd7c63dd1be9a29b777a99 /libcxxabi | |
parent | ecc70b4474302e01c1d29a672d29fb20c77608f1 (diff) | |
download | llvm-ee740b714ba0de41f48a4fb4717fa9b9a22fedf2.zip llvm-ee740b714ba0de41f48a4fb4717fa9b9a22fedf2.tar.gz llvm-ee740b714ba0de41f48a4fb4717fa9b9a22fedf2.tar.bz2 |
[Demangle] avoid more std::string_view::substr
In D148959, I removed usage of std::string_view::substr because it may
throw, and libcxxabi cannot use such code. I missed one instance in
llvm::starts_with. That is blocking copying the code back upstream in
D148566.
Mark these helpers noexcept (as they are in C++20) as well, to remind
future travelers.
Make these changes upstream, and copy them back downstream using
libcxxabi/src/demangle/cp-to-llvm.sh.
Reviewed By: #libc_abi, MaskRay, ldionne
Differential Revision: https://reviews.llvm.org/D151260
Diffstat (limited to 'libcxxabi')
-rw-r--r-- | libcxxabi/src/demangle/StringViewExtras.h | 12 |
1 files changed, 8 insertions, 4 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 |