diff options
author | Nathan Sidwell <nathan@acm.org> | 2022-01-24 15:11:59 +0300 |
---|---|---|
committer | Nathan Sidwell <nathan@acm.org> | 2022-01-24 16:28:38 +0300 |
commit | 38ffea9b4c1f59ebf434a9774cd7ae741cc87d70 (patch) | |
tree | 00edb50779fc3c000aa17294f3de1aebc118b251 /libcxxabi | |
parent | 853e79d8d8af7376a81bf692f26a0c3468811d29 (diff) |
[demangler] Resync demangler sources
Recent commits changed llvm/include/llvm/Demangle without also
changing libcxxabi/src/Demangle, which is the canonical source
location. This resyncs those commits to the libcxxabi directory.
Commits:
* 1f9e18b6565fd1bb69c4b649b9efd3467b3c7c7d
* f53d359816e66a107195e1e4b581e2a33bbafaa4
* 065044c443f4041f32e0a8d6e633f9d92580fbca
Reviewed By: ChuanqiXu
Differential Revision: https://reviews.llvm.org/D117990.diff
Diffstat (limited to 'libcxxabi')
-rw-r--r-- | libcxxabi/src/demangle/ItaniumDemangle.h | 3 | ||||
-rw-r--r-- | libcxxabi/src/demangle/StringView.h | 14 | ||||
-rw-r--r-- | libcxxabi/src/demangle/Utility.h | 9 |
3 files changed, 14 insertions, 12 deletions
diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h index b25139d8a72b..01f414a7257b 100644 --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -21,12 +21,13 @@ #include "DemangleConfig.h" #include "StringView.h" #include "Utility.h" +#include <algorithm> #include <cassert> #include <cctype> #include <cstdio> #include <cstdlib> #include <cstring> -#include <numeric> +#include <limits> #include <utility> #define FOR_EACH_NODE_KIND(X) \ diff --git a/libcxxabi/src/demangle/StringView.h b/libcxxabi/src/demangle/StringView.h index 1e4d3803f06c..7c8cb482ae1c 100644 --- a/libcxxabi/src/demangle/StringView.h +++ b/libcxxabi/src/demangle/StringView.h @@ -14,7 +14,6 @@ #define DEMANGLE_STRINGVIEW_H #include "DemangleConfig.h" -#include <algorithm> #include <cassert> #include <cstring> @@ -38,15 +37,16 @@ public: StringView substr(size_t Pos, size_t Len = npos) const { assert(Pos <= size()); - return StringView(begin() + Pos, std::min(Len, size() - Pos)); + if (Len > size() - Pos) + Len = size() - Pos; + return StringView(begin() + Pos, Len); } size_t find(char C, size_t From = 0) const { - size_t FindBegin = std::min(From, size()); // Avoid calling memchr with nullptr. - if (FindBegin < size()) { + if (From < size()) { // Just forward to memchr, which is faster than a hand-rolled loop. - if (const void *P = ::memchr(First + FindBegin, C, size() - FindBegin)) + if (const void *P = ::memchr(First + From, C, size() - From)) return size_t(static_cast<const char *>(P) - First); } return npos; @@ -98,7 +98,7 @@ public: bool startsWith(StringView Str) const { if (Str.size() > size()) return false; - return std::equal(Str.begin(), Str.end(), begin()); + return std::strncmp(Str.begin(), begin(), Str.size()) == 0; } const char &operator[](size_t Idx) const { return *(begin() + Idx); } @@ -111,7 +111,7 @@ public: inline bool operator==(const StringView &LHS, const StringView &RHS) { return LHS.size() == RHS.size() && - std::equal(LHS.begin(), LHS.end(), RHS.begin()); + std::strncmp(LHS.begin(), RHS.begin(), LHS.size()) == 0; } DEMANGLE_NAMESPACE_END diff --git a/libcxxabi/src/demangle/Utility.h b/libcxxabi/src/demangle/Utility.h index 733d83ad1b6b..587c0e4bec36 100644 --- a/libcxxabi/src/demangle/Utility.h +++ b/libcxxabi/src/demangle/Utility.h @@ -14,10 +14,11 @@ #define DEMANGLE_UTILITY_H #include "StringView.h" +#include <array> #include <cstdint> #include <cstdlib> #include <cstring> -#include <iterator> +#include <exception> #include <limits> DEMANGLE_NAMESPACE_BEGIN @@ -48,8 +49,8 @@ class OutputBuffer { return; } - char Temp[21]; - char *TempPtr = std::end(Temp); + std::array<char, 21> Temp; + char *TempPtr = Temp.data() + Temp.size(); while (N) { *--TempPtr = char('0' + N % 10); @@ -59,7 +60,7 @@ class OutputBuffer { // Add negative sign... if (isNeg) *--TempPtr = '-'; - this->operator<<(StringView(TempPtr, std::end(Temp))); + this->operator<<(StringView(TempPtr, Temp.data() + Temp.size())); } public: |