[PATCH] D152042: [Demangle] convert is*Encoding to use std::string_view
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 2 15:35:00 PDT 2023
nickdesaulniers created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This was originally a part of D149104 <https://reviews.llvm.org/D149104> which was backed out. This change
is uncontroversial though, so split it out and reland it.
Repository:
rG LLVM Github Monorepo
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.528025.patch
Type: text/x-patch
Size: 1965 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230602/1821b8e9/attachment.bin>
More information about the llvm-commits
mailing list