Skip to content

Commit d4f6ad5

Browse files
authored
[llvm-size] Avoid unneeded uses of 'raw_string_ostream::str' (NFC) (#108490)
Remove unnecessary layer of indirection.
1 parent 2fb133f commit d4f6ad5

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

llvm/tools/llvm-size/llvm-size.cpp

+15-16
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static void printDarwinSectionSizes(MachOObjectFile *MachO) {
214214
if (Load.C.cmd == MachO::LC_SEGMENT_64) {
215215
MachO::segment_command_64 Seg = MachO->getSegment64LoadCommand(Load);
216216
outs() << "Segment " << Seg.segname << ": "
217-
<< format(fmt.str().c_str(), Seg.vmsize);
217+
<< format(fmtbuf.c_str(), Seg.vmsize);
218218
if (DarwinLongFormat)
219219
outs() << " (vmaddr 0x" << format("%" PRIx64, Seg.vmaddr) << " fileoff "
220220
<< Seg.fileoff << ")";
@@ -228,20 +228,20 @@ static void printDarwinSectionSizes(MachOObjectFile *MachO) {
228228
<< format("%.16s", &Sec.sectname) << "): ";
229229
else
230230
outs() << "\tSection " << format("%.16s", &Sec.sectname) << ": ";
231-
outs() << format(fmt.str().c_str(), Sec.size);
231+
outs() << format(fmtbuf.c_str(), Sec.size);
232232
if (DarwinLongFormat)
233233
outs() << " (addr 0x" << format("%" PRIx64, Sec.addr) << " offset "
234234
<< Sec.offset << ")";
235235
outs() << "\n";
236236
sec_total += Sec.size;
237237
}
238238
if (Seg.nsects != 0)
239-
outs() << "\ttotal " << format(fmt.str().c_str(), sec_total) << "\n";
239+
outs() << "\ttotal " << format(fmtbuf.c_str(), sec_total) << "\n";
240240
} else if (Load.C.cmd == MachO::LC_SEGMENT) {
241241
MachO::segment_command Seg = MachO->getSegmentLoadCommand(Load);
242242
uint64_t Seg_vmsize = Seg.vmsize;
243243
outs() << "Segment " << Seg.segname << ": "
244-
<< format(fmt.str().c_str(), Seg_vmsize);
244+
<< format(fmtbuf.c_str(), Seg_vmsize);
245245
if (DarwinLongFormat)
246246
outs() << " (vmaddr 0x" << format("%" PRIx32, Seg.vmaddr) << " fileoff "
247247
<< Seg.fileoff << ")";
@@ -256,18 +256,18 @@ static void printDarwinSectionSizes(MachOObjectFile *MachO) {
256256
else
257257
outs() << "\tSection " << format("%.16s", &Sec.sectname) << ": ";
258258
uint64_t Sec_size = Sec.size;
259-
outs() << format(fmt.str().c_str(), Sec_size);
259+
outs() << format(fmtbuf.c_str(), Sec_size);
260260
if (DarwinLongFormat)
261261
outs() << " (addr 0x" << format("%" PRIx32, Sec.addr) << " offset "
262262
<< Sec.offset << ")";
263263
outs() << "\n";
264264
sec_total += Sec.size;
265265
}
266266
if (Seg.nsects != 0)
267-
outs() << "\ttotal " << format(fmt.str().c_str(), sec_total) << "\n";
267+
outs() << "\ttotal " << format(fmtbuf.c_str(), sec_total) << "\n";
268268
}
269269
}
270-
outs() << "total " << format(fmt.str().c_str(), total) << "\n";
270+
outs() << "total " << format(fmtbuf.c_str(), total) << "\n";
271271
}
272272

273273
/// Print the summary sizes of the standard Mach-O segments in @p MachO.
@@ -399,7 +399,7 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
399399
<< "%" << max_addr_len << "s\n";
400400

401401
// Print header
402-
outs() << format(fmt.str().c_str(), static_cast<const char *>("section"),
402+
outs() << format(fmtbuf.c_str(), static_cast<const char *>("section"),
403403
static_cast<const char *>("size"),
404404
static_cast<const char *>("addr"));
405405
fmtbuf.clear();
@@ -422,13 +422,13 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
422422

423423
uint64_t size = Section.getSize();
424424
uint64_t addr = Section.getAddress();
425-
outs() << format(fmt.str().c_str(), name_or_err->str().c_str(), size, addr);
425+
outs() << format(fmtbuf.c_str(), name_or_err->str().c_str(), size, addr);
426426
}
427427

428428
if (ELFCommons) {
429429
if (Expected<uint64_t> CommonSizeOrErr = getCommonSize(Obj)) {
430430
total += *CommonSizeOrErr;
431-
outs() << format(fmt.str().c_str(), std::string("*COM*").c_str(),
431+
outs() << format(fmtbuf.c_str(), std::string("*COM*").c_str(),
432432
*CommonSizeOrErr, static_cast<uint64_t>(0));
433433
} else {
434434
error(CommonSizeOrErr.takeError(), Obj->getFileName());
@@ -440,8 +440,7 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
440440
fmtbuf.clear();
441441
fmt << "%-" << max_name_len << "s "
442442
<< "%#" << max_size_len << radix_fmt << "\n";
443-
outs() << format(fmt.str().c_str(), static_cast<const char *>("Total"),
444-
total)
443+
outs() << format(fmtbuf.c_str(), static_cast<const char *>("Total"), total)
445444
<< "\n\n";
446445
} else {
447446
// The Berkeley format does not display individual section sizes. It
@@ -498,11 +497,11 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
498497
fmt << "%#7" << radix_fmt << "\t"
499498
<< "%#7" << radix_fmt << "\t"
500499
<< "%#7" << radix_fmt << "\t";
501-
outs() << format(fmt.str().c_str(), total_text, total_data, total_bss);
500+
outs() << format(fmtbuf.c_str(), total_text, total_data, total_bss);
502501
fmtbuf.clear();
503502
fmt << "%7" << (Radix == octal ? PRIo64 : PRIu64) << "\t"
504503
<< "%7" PRIx64 "\t";
505-
outs() << format(fmt.str().c_str(), total, total);
504+
outs() << format(fmtbuf.c_str(), total, total);
506505
}
507506
}
508507

@@ -852,12 +851,12 @@ static void printBerkeleyTotals() {
852851
fmt << "%#7" << radix_fmt << "\t"
853852
<< "%#7" << radix_fmt << "\t"
854853
<< "%#7" << radix_fmt << "\t";
855-
outs() << format(fmt.str().c_str(), TotalObjectText, TotalObjectData,
854+
outs() << format(fmtbuf.c_str(), TotalObjectText, TotalObjectData,
856855
TotalObjectBss);
857856
fmtbuf.clear();
858857
fmt << "%7" << (Radix == octal ? PRIo64 : PRIu64) << "\t"
859858
<< "%7" PRIx64 "\t";
860-
outs() << format(fmt.str().c_str(), TotalObjectTotal, TotalObjectTotal)
859+
outs() << format(fmtbuf.c_str(), TotalObjectTotal, TotalObjectTotal)
861860
<< "(TOTALS)\n";
862861
}
863862

0 commit comments

Comments
 (0)