Skip to content

Commit

Permalink
[Demangle] use std::string_view::data rather than &*std::string_view:…
Browse files Browse the repository at this point in the history
…:begin

To fix expensive check builds that were failing when using MSVC's
std::string_view::iterator::operator*, I added a few expressions like
&*std::string_view::begin.  @nico pointed out that this is literally the
same thing and more clearly expressed as std::string_view::data.

Link: #63740

Reviewed By: #libc_abi, ldionne, philnik, MaskRay

Differential Revision: https://reviews.llvm.org/D154876
  • Loading branch information
nickdesaulniers committed Jul 13, 2023
1 parent e909a2c commit 8bb9414
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions libcxxabi/src/demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,7 @@ template <class Float> class FloatLiteralImpl : public Node {
Float value;
char buf[sizeof(Float)];
};
const char *t = &*Contents.begin();
const char *t = Contents.data();
const char *last = t + N;
char *e = buf;
for (; t != last; ++t, ++e) {
Expand Down Expand Up @@ -3719,7 +3719,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseQualifiedType() {
std::string_view ProtoSourceName(Qual.data() + Len, Qual.size() - Len);
std::string_view Proto;
{
ScopedOverride<const char *> SaveFirst(First, &*ProtoSourceName.begin()),
ScopedOverride<const char *> SaveFirst(First, ProtoSourceName.data()),
SaveLast(Last, &*ProtoSourceName.rbegin() + 1);
Proto = parseBareSourceName();
}
Expand Down
5 changes: 2 additions & 3 deletions llvm/include/llvm/Demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,7 @@ template <class Float> class FloatLiteralImpl : public Node {
Float value;
char buf[sizeof(Float)];
};
const char *t = &*Contents.begin();
const char *t = Contents.data();
const char *last = t + N;
char *e = buf;
for (; t != last; ++t, ++e) {
Expand Down Expand Up @@ -3714,8 +3714,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseQualifiedType() {
std::string_view ProtoSourceName(Qual.data() + Len, Qual.size() - Len);
std::string_view Proto;
{
ScopedOverride<const char *> SaveFirst(First,
&*ProtoSourceName.begin()),
ScopedOverride<const char *> SaveFirst(First, ProtoSourceName.data()),
SaveLast(Last, &*ProtoSourceName.rbegin() + 1);
Proto = parseBareSourceName();
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Demangle/ItaniumDemangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct DumpVisitor {

void printStr(const char *S) { fprintf(stderr, "%s", S); }
void print(std::string_view SV) {
fprintf(stderr, "\"%.*s\"", (int)SV.size(), &*SV.begin());
fprintf(stderr, "\"%.*s\"", (int)SV.size(), SV.data());
}
void print(const Node *N) {
if (N)
Expand Down
11 changes: 5 additions & 6 deletions llvm/lib/Demangle/MicrosoftDemangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ std::string_view Demangler::copyString(std::string_view Borrowed) {
// This is not a micro-optimization, it avoids UB, should Borrowed be an null
// buffer.
if (Borrowed.size())
std::memcpy(Stable, &*Borrowed.begin(), Borrowed.size());
std::memcpy(Stable, Borrowed.data(), Borrowed.size());

return {Stable, Borrowed.size()};
}
Expand Down Expand Up @@ -792,7 +792,7 @@ SymbolNode *Demangler::demangleMD5Name(std::string_view &MangledName) {
Error = true;
return nullptr;
}
const char *Start = &*MangledName.begin();
const char *Start = MangledName.data();
const size_t StartSize = MangledName.size();
MangledName.remove_prefix(MD5Last + 1);

Expand Down Expand Up @@ -2382,7 +2382,7 @@ void Demangler::dumpBackReferences() {
T->output(OB, OF_Default);

std::string_view B = OB;
std::printf(" [%d] - %.*s\n", (int)I, (int)B.size(), &*B.begin());
std::printf(" [%d] - %.*s\n", (int)I, (int)B.size(), B.data());
}
std::free(OB.getBuffer());

Expand All @@ -2391,7 +2391,7 @@ void Demangler::dumpBackReferences() {
std::printf("%d name backreferences\n", (int)Backrefs.NamesCount);
for (size_t I = 0; I < Backrefs.NamesCount; ++I) {
std::printf(" [%d] - %.*s\n", (int)I, (int)Backrefs.Names[I]->Name.size(),
&*Backrefs.Names[I]->Name.begin());
Backrefs.Names[I]->Name.data());
}
if (Backrefs.NamesCount > 0)
std::printf("\n");
Expand All @@ -2404,8 +2404,7 @@ char *llvm::microsoftDemangle(std::string_view MangledName, size_t *NMangled,
std::string_view Name{MangledName};
SymbolNode *AST = D.parse(Name);
if (!D.Error && NMangled)
*NMangled = Name.empty() ? MangledName.size()
: &*Name.begin() - &*MangledName.begin();
*NMangled = MangledName.size() - Name.size();

if (Flags & MSDF_DumpBackrefs)
D.dumpBackReferences();
Expand Down

0 comments on commit 8bb9414

Please sign in to comment.