diff options
Diffstat (limited to 'externals/demangle/llvm/Demangle/StringView.h')
| -rw-r--r-- | externals/demangle/llvm/Demangle/StringView.h | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/externals/demangle/llvm/Demangle/StringView.h b/externals/demangle/llvm/Demangle/StringView.h index 44d2b18a3..76b215252 100644 --- a/externals/demangle/llvm/Demangle/StringView.h +++ b/externals/demangle/llvm/Demangle/StringView.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | //===--- StringView.h -------------------------------------------*- C++ -*-===// | 1 | //===--- StringView.h ----------------*- mode:c++;eval:(read-only-mode) -*-===// |
| 2 | // | 2 | // Do not edit! See README.txt. |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. | 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-FileCopyrightText: Part of the LLVM Project | 5 | // SPDX-FileCopyrightText: Part of the LLVM Project |
| @@ -8,6 +8,9 @@ | |||
| 8 | //===----------------------------------------------------------------------===// | 8 | //===----------------------------------------------------------------------===// |
| 9 | // | 9 | // |
| 10 | // FIXME: Use std::string_view instead when we support C++17. | 10 | // FIXME: Use std::string_view instead when we support C++17. |
| 11 | // There are two copies of this file in the source tree. The one under | ||
| 12 | // libcxxabi is the original and the one under llvm is the copy. Use | ||
| 13 | // cp-to-llvm.sh to update the copy. See README.txt for more details. | ||
| 11 | // | 14 | // |
| 12 | //===----------------------------------------------------------------------===// | 15 | //===----------------------------------------------------------------------===// |
| 13 | 16 | ||
| @@ -15,7 +18,6 @@ | |||
| 15 | #define DEMANGLE_STRINGVIEW_H | 18 | #define DEMANGLE_STRINGVIEW_H |
| 16 | 19 | ||
| 17 | #include "DemangleConfig.h" | 20 | #include "DemangleConfig.h" |
| 18 | #include <algorithm> | ||
| 19 | #include <cassert> | 21 | #include <cassert> |
| 20 | #include <cstring> | 22 | #include <cstring> |
| 21 | 23 | ||
| @@ -37,29 +39,23 @@ public: | |||
| 37 | StringView(const char *Str) : First(Str), Last(Str + std::strlen(Str)) {} | 39 | StringView(const char *Str) : First(Str), Last(Str + std::strlen(Str)) {} |
| 38 | StringView() : First(nullptr), Last(nullptr) {} | 40 | StringView() : First(nullptr), Last(nullptr) {} |
| 39 | 41 | ||
| 40 | StringView substr(size_t From) const { | 42 | StringView substr(size_t Pos, size_t Len = npos) const { |
| 41 | return StringView(begin() + From, size() - From); | 43 | assert(Pos <= size()); |
| 44 | if (Len > size() - Pos) | ||
| 45 | Len = size() - Pos; | ||
| 46 | return StringView(begin() + Pos, Len); | ||
| 42 | } | 47 | } |
| 43 | 48 | ||
| 44 | size_t find(char C, size_t From = 0) const { | 49 | size_t find(char C, size_t From = 0) const { |
| 45 | size_t FindBegin = std::min(From, size()); | ||
| 46 | // Avoid calling memchr with nullptr. | 50 | // Avoid calling memchr with nullptr. |
| 47 | if (FindBegin < size()) { | 51 | if (From < size()) { |
| 48 | // Just forward to memchr, which is faster than a hand-rolled loop. | 52 | // Just forward to memchr, which is faster than a hand-rolled loop. |
| 49 | if (const void *P = ::memchr(First + FindBegin, C, size() - FindBegin)) | 53 | if (const void *P = ::memchr(First + From, C, size() - From)) |
| 50 | return size_t(static_cast<const char *>(P) - First); | 54 | return size_t(static_cast<const char *>(P) - First); |
| 51 | } | 55 | } |
| 52 | return npos; | 56 | return npos; |
| 53 | } | 57 | } |
| 54 | 58 | ||
| 55 | StringView substr(size_t From, size_t To) const { | ||
| 56 | if (To >= size()) | ||
| 57 | To = size() - 1; | ||
| 58 | if (From >= size()) | ||
| 59 | From = size() - 1; | ||
| 60 | return StringView(First + From, First + To); | ||
| 61 | } | ||
| 62 | |||
| 63 | StringView dropFront(size_t N = 1) const { | 59 | StringView dropFront(size_t N = 1) const { |
| 64 | if (N >= size()) | 60 | if (N >= size()) |
| 65 | N = size(); | 61 | N = size(); |
| @@ -106,7 +102,7 @@ public: | |||
| 106 | bool startsWith(StringView Str) const { | 102 | bool startsWith(StringView Str) const { |
| 107 | if (Str.size() > size()) | 103 | if (Str.size() > size()) |
| 108 | return false; | 104 | return false; |
| 109 | return std::equal(Str.begin(), Str.end(), begin()); | 105 | return std::strncmp(Str.begin(), begin(), Str.size()) == 0; |
| 110 | } | 106 | } |
| 111 | 107 | ||
| 112 | const char &operator[](size_t Idx) const { return *(begin() + Idx); } | 108 | const char &operator[](size_t Idx) const { return *(begin() + Idx); } |
| @@ -119,7 +115,7 @@ public: | |||
| 119 | 115 | ||
| 120 | inline bool operator==(const StringView &LHS, const StringView &RHS) { | 116 | inline bool operator==(const StringView &LHS, const StringView &RHS) { |
| 121 | return LHS.size() == RHS.size() && | 117 | return LHS.size() == RHS.size() && |
| 122 | std::equal(LHS.begin(), LHS.end(), RHS.begin()); | 118 | std::strncmp(LHS.begin(), RHS.begin(), LHS.size()) == 0; |
| 123 | } | 119 | } |
| 124 | 120 | ||
| 125 | DEMANGLE_NAMESPACE_END | 121 | DEMANGLE_NAMESPACE_END |