[PATCH] D152042: [Demangle] convert is*Encoding to use std::string_view
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 5 09:39:06 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG936dcc89da4f: [Demangle] convert is*Encoding to use std::string_view (authored by nickdesaulniers).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152042/new/
https://reviews.llvm.org/D152042
Files:
llvm/lib/Demangle/Demangle.cpp
Index: llvm/lib/Demangle/Demangle.cpp
===================================================================
--- llvm/lib/Demangle/Demangle.cpp
+++ llvm/lib/Demangle/Demangle.cpp
@@ -11,20 +11,11 @@
//===----------------------------------------------------------------------===//
#include "llvm/Demangle/Demangle.h"
+#include "llvm/Demangle/StringViewExtras.h"
#include <cstdlib>
#include <cstring>
-static bool isItaniumEncoding(const char *S) {
- // Itanium encoding requires 1 or 3 leading underscores, followed by 'Z'.
- return std::strncmp(S, "_Z", 2) == 0 || std::strncmp(S, "___Z", 4) == 0;
-}
-
-static bool isRustEncoding(const char *S) { return S[0] == '_' && S[1] == 'R'; }
-
-static bool isDLangEncoding(const std::string &MangledName) {
- return MangledName.size() >= 2 && MangledName[0] == '_' &&
- MangledName[1] == 'D';
-}
+using llvm::itanium_demangle::starts_with;
std::string llvm::demangle(const std::string &MangledName) {
std::string Result;
@@ -45,14 +36,23 @@
return MangledName;
}
+static bool isItaniumEncoding(std::string_view S) {
+ // Itanium encoding requires 1 or 3 leading underscores, followed by 'Z'.
+ return starts_with(S, "_Z") || starts_with(S, "___Z");
+}
+
+static bool isRustEncoding(std::string_view S) { return starts_with(S, "_R"); }
+
+static bool isDLangEncoding(std::string_view S) { return starts_with(S, "_D"); }
+
bool llvm::nonMicrosoftDemangle(std::string_view MangledName,
std::string &Result) {
char *Demangled = nullptr;
- if (isItaniumEncoding(MangledName.data()))
+ if (isItaniumEncoding(MangledName))
Demangled = itaniumDemangle(MangledName);
- else if (isRustEncoding(MangledName.data()))
+ else if (isRustEncoding(MangledName))
Demangled = rustDemangle(MangledName);
- else if (isDLangEncoding(MangledName.data()))
+ else if (isDLangEncoding(MangledName))
Demangled = dlangDemangle(MangledName);
if (!Demangled)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152042.528479.patch
Type: text/x-patch
Size: 1965 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230605/d1abcc9c/attachment.bin>
More information about the llvm-commits
mailing list