[llvm] Remove redundant str() and c_str() (NFC) (#166012)

io.mapRequired takes StringRef as the key type.  As such, we do not
need to create extraneous copies with str().c_str() or str().

Identified with readability-redundant-string-cstr.
This commit is contained in:
Kazu Hirata 2025-11-01 12:42:06 -07:00 committed by GitHub
parent 61e966ec90
commit e7a23c4020
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 19 additions and 20 deletions

View File

@ -79,7 +79,7 @@ struct CustomMappingTraits<
}
Args.push_back(Arg);
}
io.mapRequired(Key.str().c_str(), V[Args]);
io.mapRequired(Key, V[Args]);
}
static void output(
IO &io,
@ -91,7 +91,7 @@ struct CustomMappingTraits<
Key += ',';
Key += llvm::utostr(Arg);
}
io.mapRequired(Key.c_str(), P.second);
io.mapRequired(Key, P.second);
}
}
};
@ -122,11 +122,11 @@ struct CustomMappingTraits<std::map<uint64_t, WholeProgramDevirtResolution>> {
io.setError("key not an integer");
return;
}
io.mapRequired(Key.str().c_str(), V[KeyInt]);
io.mapRequired(Key, V[KeyInt]);
}
static void output(IO &io, std::map<uint64_t, WholeProgramDevirtResolution> &V) {
for (auto &P : V)
io.mapRequired(llvm::utostr(P.first).c_str(), P.second);
io.mapRequired(llvm::utostr(P.first), P.second);
}
};
@ -215,7 +215,7 @@ namespace yaml {
template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
static void inputOne(IO &io, StringRef Key, GlobalValueSummaryMapTy &V) {
std::vector<GlobalValueSummaryYaml> GVSums;
io.mapRequired(Key.str().c_str(), GVSums);
io.mapRequired(Key, GVSums);
uint64_t KeyInt;
if (Key.getAsInteger(0, KeyInt)) {
io.setError("key not an integer");
@ -290,7 +290,7 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
}
}
if (!GVSums.empty())
io.mapRequired(llvm::utostr(P.first).c_str(), GVSums);
io.mapRequired(llvm::utostr(P.first), GVSums);
}
}
static void fixAliaseeLinks(GlobalValueSummaryMapTy &V) {
@ -313,12 +313,12 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
template <> struct CustomMappingTraits<TypeIdSummaryMapTy> {
static void inputOne(IO &io, StringRef Key, TypeIdSummaryMapTy &V) {
TypeIdSummary TId;
io.mapRequired(Key.str().c_str(), TId);
io.mapRequired(Key, TId);
V.insert({GlobalValue::getGUIDAssumingExternalLinkage(Key), {Key, TId}});
}
static void output(IO &io, TypeIdSummaryMapTy &V) {
for (auto &TidIter : V)
io.mapRequired(TidIter.second.first.str().c_str(), TidIter.second.second);
io.mapRequired(TidIter.second.first, TidIter.second.second);
}
};

View File

@ -141,7 +141,7 @@ template <> struct CustomMappingTraits<memprof::PortableMemInfoBlock> {
#define MIBEntryDef(NameTag, Name, Type) \
if (KeyStr == #Name) { \
uint64_t Value; \
Io.mapRequired(KeyStr.str().c_str(), Value); \
Io.mapRequired(KeyStr, Value); \
MIB.Name = static_cast<Type>(Value); \
MIB.Schema.set(llvm::to_underlying(memprof::Meta::Name)); \
return; \

View File

@ -1921,12 +1921,12 @@ template <typename T> struct StdMapStringCustomMappingTraitsImpl {
using map_type = std::map<std::string, T>;
static void inputOne(IO &io, StringRef key, map_type &v) {
io.mapRequired(key.str().c_str(), v[std::string(key)]);
io.mapRequired(key, v[std::string(key)]);
}
static void output(IO &io, map_type &v) {
for (auto &p : v)
io.mapRequired(p.first.c_str(), p.second);
io.mapRequired(p.first, p.second);
}
};

View File

@ -209,12 +209,12 @@ template <> struct CustomMappingTraits<MapDocNode> {
static void inputOne(IO &IO, StringRef Key, MapDocNode &M) {
ScalarDocNode KeyObj = M.getDocument()->getNode();
KeyObj.fromString(Key, "");
IO.mapRequired(Key.str().c_str(), M.getMap()[KeyObj]);
IO.mapRequired(Key, M.getMap()[KeyObj]);
}
static void output(IO &IO, MapDocNode &M) {
for (auto I : M.getMap()) {
IO.mapRequired(I.first.toString().c_str(), I.second);
IO.mapRequired(I.first.toString(), I.second);
}
}
};

View File

@ -37,7 +37,7 @@ template <> struct MappingTraits<HashNodeStable> {
template <> struct CustomMappingTraits<IdHashNodeStableMapTy> {
static void inputOne(IO &io, StringRef Key, IdHashNodeStableMapTy &V) {
HashNodeStable NodeStable;
io.mapRequired(Key.str().c_str(), NodeStable);
io.mapRequired(Key, NodeStable);
unsigned Id;
if (Key.getAsInteger(0, Id)) {
io.setError("Id not an integer");
@ -48,7 +48,7 @@ template <> struct CustomMappingTraits<IdHashNodeStableMapTy> {
static void output(IO &io, IdHashNodeStableMapTy &V) {
for (auto Iter = V.begin(); Iter != V.end(); ++Iter)
io.mapRequired(utostr(Iter->first).c_str(), Iter->second);
io.mapRequired(utostr(Iter->first), Iter->second);
}
};

View File

@ -207,8 +207,7 @@ template <> struct MappingTraits<WebAssemblyFunctionInfo> {
template <> struct CustomMappingTraits<BBNumberMap> {
static void inputOne(IO &YamlIO, StringRef Key,
BBNumberMap &SrcToUnwindDest) {
YamlIO.mapRequired(Key.str().c_str(),
SrcToUnwindDest[std::atoi(Key.str().c_str())]);
YamlIO.mapRequired(Key, SrcToUnwindDest[std::atoi(Key.str().c_str())]);
}
static void output(IO &YamlIO, BBNumberMap &SrcToUnwindDest) {

View File

@ -202,7 +202,7 @@ struct CustomMappingTraits<std::map<exegesis::ValidationEvent, int64_t>> {
Io.setError("Key is not a valid validation event");
return;
}
Io.mapRequired(KeyStr.str().c_str(), VI[*Key]);
Io.mapRequired(KeyStr, VI[*Key]);
}
static void output(IO &Io, std::map<exegesis::ValidationEvent, int64_t> &VI) {

View File

@ -3221,12 +3221,12 @@ template <> struct TaggedScalarTraits<Scalar> {
template <> struct CustomMappingTraits<Map> {
static void inputOne(IO &IO, StringRef Key, Map &M) {
IO.mapRequired(Key.str().c_str(), M[Key]);
IO.mapRequired(Key, M[Key]);
}
static void output(IO &IO, Map &M) {
for (auto &N : M)
IO.mapRequired(N.getKey().str().c_str(), N.getValue());
IO.mapRequired(N.getKey(), N.getValue());
}
};