Skip to content

Commit e7a23c4

Browse files
[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.
1 parent 61e966e commit e7a23c4

File tree

8 files changed

+19
-20
lines changed

8 files changed

+19
-20
lines changed

llvm/include/llvm/IR/ModuleSummaryIndexYAML.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct CustomMappingTraits<
7979
}
8080
Args.push_back(Arg);
8181
}
82-
io.mapRequired(Key.str().c_str(), V[Args]);
82+
io.mapRequired(Key, V[Args]);
8383
}
8484
static void output(
8585
IO &io,
@@ -91,7 +91,7 @@ struct CustomMappingTraits<
9191
Key += ',';
9292
Key += llvm::utostr(Arg);
9393
}
94-
io.mapRequired(Key.c_str(), P.second);
94+
io.mapRequired(Key, P.second);
9595
}
9696
}
9797
};
@@ -122,11 +122,11 @@ struct CustomMappingTraits<std::map<uint64_t, WholeProgramDevirtResolution>> {
122122
io.setError("key not an integer");
123123
return;
124124
}
125-
io.mapRequired(Key.str().c_str(), V[KeyInt]);
125+
io.mapRequired(Key, V[KeyInt]);
126126
}
127127
static void output(IO &io, std::map<uint64_t, WholeProgramDevirtResolution> &V) {
128128
for (auto &P : V)
129-
io.mapRequired(llvm::utostr(P.first).c_str(), P.second);
129+
io.mapRequired(llvm::utostr(P.first), P.second);
130130
}
131131
};
132132

@@ -215,7 +215,7 @@ namespace yaml {
215215
template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
216216
static void inputOne(IO &io, StringRef Key, GlobalValueSummaryMapTy &V) {
217217
std::vector<GlobalValueSummaryYaml> GVSums;
218-
io.mapRequired(Key.str().c_str(), GVSums);
218+
io.mapRequired(Key, GVSums);
219219
uint64_t KeyInt;
220220
if (Key.getAsInteger(0, KeyInt)) {
221221
io.setError("key not an integer");
@@ -290,7 +290,7 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
290290
}
291291
}
292292
if (!GVSums.empty())
293-
io.mapRequired(llvm::utostr(P.first).c_str(), GVSums);
293+
io.mapRequired(llvm::utostr(P.first), GVSums);
294294
}
295295
}
296296
static void fixAliaseeLinks(GlobalValueSummaryMapTy &V) {
@@ -313,12 +313,12 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
313313
template <> struct CustomMappingTraits<TypeIdSummaryMapTy> {
314314
static void inputOne(IO &io, StringRef Key, TypeIdSummaryMapTy &V) {
315315
TypeIdSummary TId;
316-
io.mapRequired(Key.str().c_str(), TId);
316+
io.mapRequired(Key, TId);
317317
V.insert({GlobalValue::getGUIDAssumingExternalLinkage(Key), {Key, TId}});
318318
}
319319
static void output(IO &io, TypeIdSummaryMapTy &V) {
320320
for (auto &TidIter : V)
321-
io.mapRequired(TidIter.second.first.str().c_str(), TidIter.second.second);
321+
io.mapRequired(TidIter.second.first, TidIter.second.second);
322322
}
323323
};
324324

llvm/include/llvm/ProfileData/MemProfYAML.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ template <> struct CustomMappingTraits<memprof::PortableMemInfoBlock> {
141141
#define MIBEntryDef(NameTag, Name, Type) \
142142
if (KeyStr == #Name) { \
143143
uint64_t Value; \
144-
Io.mapRequired(KeyStr.str().c_str(), Value); \
144+
Io.mapRequired(KeyStr, Value); \
145145
MIB.Name = static_cast<Type>(Value); \
146146
MIB.Schema.set(llvm::to_underlying(memprof::Meta::Name)); \
147147
return; \

llvm/include/llvm/Support/YAMLTraits.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,12 +1921,12 @@ template <typename T> struct StdMapStringCustomMappingTraitsImpl {
19211921
using map_type = std::map<std::string, T>;
19221922

19231923
static void inputOne(IO &io, StringRef key, map_type &v) {
1924-
io.mapRequired(key.str().c_str(), v[std::string(key)]);
1924+
io.mapRequired(key, v[std::string(key)]);
19251925
}
19261926

19271927
static void output(IO &io, map_type &v) {
19281928
for (auto &p : v)
1929-
io.mapRequired(p.first.c_str(), p.second);
1929+
io.mapRequired(p.first, p.second);
19301930
}
19311931
};
19321932

llvm/lib/BinaryFormat/MsgPackDocumentYAML.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ template <> struct CustomMappingTraits<MapDocNode> {
209209
static void inputOne(IO &IO, StringRef Key, MapDocNode &M) {
210210
ScalarDocNode KeyObj = M.getDocument()->getNode();
211211
KeyObj.fromString(Key, "");
212-
IO.mapRequired(Key.str().c_str(), M.getMap()[KeyObj]);
212+
IO.mapRequired(Key, M.getMap()[KeyObj]);
213213
}
214214

215215
static void output(IO &IO, MapDocNode &M) {
216216
for (auto I : M.getMap()) {
217-
IO.mapRequired(I.first.toString().c_str(), I.second);
217+
IO.mapRequired(I.first.toString(), I.second);
218218
}
219219
}
220220
};

llvm/lib/CGData/OutlinedHashTreeRecord.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ template <> struct MappingTraits<HashNodeStable> {
3737
template <> struct CustomMappingTraits<IdHashNodeStableMapTy> {
3838
static void inputOne(IO &io, StringRef Key, IdHashNodeStableMapTy &V) {
3939
HashNodeStable NodeStable;
40-
io.mapRequired(Key.str().c_str(), NodeStable);
40+
io.mapRequired(Key, NodeStable);
4141
unsigned Id;
4242
if (Key.getAsInteger(0, Id)) {
4343
io.setError("Id not an integer");
@@ -48,7 +48,7 @@ template <> struct CustomMappingTraits<IdHashNodeStableMapTy> {
4848

4949
static void output(IO &io, IdHashNodeStableMapTy &V) {
5050
for (auto Iter = V.begin(); Iter != V.end(); ++Iter)
51-
io.mapRequired(utostr(Iter->first).c_str(), Iter->second);
51+
io.mapRequired(utostr(Iter->first), Iter->second);
5252
}
5353
};
5454

llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ template <> struct MappingTraits<WebAssemblyFunctionInfo> {
207207
template <> struct CustomMappingTraits<BBNumberMap> {
208208
static void inputOne(IO &YamlIO, StringRef Key,
209209
BBNumberMap &SrcToUnwindDest) {
210-
YamlIO.mapRequired(Key.str().c_str(),
211-
SrcToUnwindDest[std::atoi(Key.str().c_str())]);
210+
YamlIO.mapRequired(Key, SrcToUnwindDest[std::atoi(Key.str().c_str())]);
212211
}
213212

214213
static void output(IO &YamlIO, BBNumberMap &SrcToUnwindDest) {

llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ struct CustomMappingTraits<std::map<exegesis::ValidationEvent, int64_t>> {
202202
Io.setError("Key is not a valid validation event");
203203
return;
204204
}
205-
Io.mapRequired(KeyStr.str().c_str(), VI[*Key]);
205+
Io.mapRequired(KeyStr, VI[*Key]);
206206
}
207207

208208
static void output(IO &Io, std::map<exegesis::ValidationEvent, int64_t> &VI) {

llvm/unittests/Support/YAMLIOTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,12 +3221,12 @@ template <> struct TaggedScalarTraits<Scalar> {
32213221

32223222
template <> struct CustomMappingTraits<Map> {
32233223
static void inputOne(IO &IO, StringRef Key, Map &M) {
3224-
IO.mapRequired(Key.str().c_str(), M[Key]);
3224+
IO.mapRequired(Key, M[Key]);
32253225
}
32263226

32273227
static void output(IO &IO, Map &M) {
32283228
for (auto &N : M)
3229-
IO.mapRequired(N.getKey().str().c_str(), N.getValue());
3229+
IO.mapRequired(N.getKey(), N.getValue());
32303230
}
32313231
};
32323232

0 commit comments

Comments
 (0)