[lld] r326841 - Do not create temporary strings just to print out spaces. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 6 14:48:46 PST 2018


Author: ruiu
Date: Tue Mar  6 14:48:46 2018
New Revision: 326841

URL: http://llvm.org/viewvc/llvm-project?rev=326841&view=rev
Log:
Do not create temporary strings just to print out spaces. NFC.

Modified:
    lld/trunk/COFF/MapFile.cpp
    lld/trunk/ELF/MapFile.cpp

Modified: lld/trunk/COFF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MapFile.cpp?rev=326841&r1=326840&r2=326841&view=diff
==============================================================================
--- lld/trunk/COFF/MapFile.cpp (original)
+++ lld/trunk/COFF/MapFile.cpp Tue Mar  6 14:48:46 2018
@@ -36,14 +36,15 @@ using namespace lld::coff;
 typedef DenseMap<const SectionChunk *, SmallVector<DefinedRegular *, 4>>
     SymbolMapTy;
 
+static const std::string Indent1 = "        ";         // 8 spaces
+static const std::string Indent2 = "                "; // 16 spaces
+
 // Print out the first three columns of a line.
 static void writeHeader(raw_ostream &OS, uint64_t Addr, uint64_t Size,
                         uint64_t Align) {
   OS << format("%08llx %08llx %5lld ", Addr, Size, Align);
 }
 
-static std::string indent(int Depth) { return std::string(Depth * 8, ' '); }
-
 // Returns a list of all symbols that we want to print out.
 static std::vector<DefinedRegular *> getSymbols() {
   std::vector<DefinedRegular *> V;
@@ -78,7 +79,7 @@ getSymbolStrings(ArrayRef<DefinedRegular
   for_each_n(parallel::par, (size_t)0, Syms.size(), [&](size_t I) {
     raw_string_ostream OS(Str[I]);
     writeHeader(OS, Syms[I]->getRVA(), 0, 0);
-    OS << indent(2) << toString(*Syms[I]);
+    OS << Indent2 << toString(*Syms[I]);
   });
 
   DenseMap<DefinedRegular *, std::string> Ret;
@@ -115,7 +116,7 @@ void coff::writeMapFile(ArrayRef<OutputS
         continue;
 
       writeHeader(OS, SC->getRVA(), SC->getSize(), SC->Alignment);
-      OS << indent(1) << SC->File->getName() << ":(" << SC->getSectionName()
+      OS << Indent1 << SC->File->getName() << ":(" << SC->getSectionName()
          << ")\n";
       for (DefinedRegular *Sym : SectionSyms[SC])
         OS << SymStr[Sym] << '\n';

Modified: lld/trunk/ELF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MapFile.cpp?rev=326841&r1=326840&r2=326841&view=diff
==============================================================================
--- lld/trunk/ELF/MapFile.cpp (original)
+++ lld/trunk/ELF/MapFile.cpp Tue Mar  6 14:48:46 2018
@@ -38,6 +38,9 @@ using namespace lld::elf;
 
 typedef DenseMap<const SectionBase *, SmallVector<Symbol *, 4>> SymbolMapTy;
 
+static const std::string Indent1 = "        ";         // 8 spaces
+static const std::string Indent2 = "                "; // 16 spaces
+
 // Print out the first three columns of a line.
 static void writeHeader(raw_ostream &OS, uint64_t Addr, uint64_t Size,
                         uint64_t Align) {
@@ -45,8 +48,6 @@ static void writeHeader(raw_ostream &OS,
   OS << format("%0*llx %0*llx %5lld ", W, Addr, W, Size, Align);
 }
 
-static std::string indent(int Depth) { return std::string(Depth * 8, ' '); }
-
 // Returns a list of all symbols that we want to print out.
 static std::vector<Symbol *> getSymbols() {
   std::vector<Symbol *> V;
@@ -100,7 +101,7 @@ getSymbolStrings(ArrayRef<Symbol *> Syms
   parallelForEachN(0, Syms.size(), [&](size_t I) {
     raw_string_ostream OS(Str[I]);
     writeHeader(OS, Syms[I]->getVA(), Syms[I]->getSize(), 0);
-    OS << indent(2) << toString(*Syms[I]);
+    OS << Indent2 << toString(*Syms[I]);
   });
 
   DenseMap<Symbol *, std::string> Ret;
@@ -139,7 +140,7 @@ void elf::writeMapFile() {
     // Dump symbols for each input section.
     for (InputSection *IS : getInputSections(OSec)) {
       writeHeader(OS, OSec->Addr + IS->OutSecOff, IS->getSize(), IS->Alignment);
-      OS << indent(1) << toString(IS) << '\n';
+      OS << Indent1 << toString(IS) << '\n';
       for (Symbol *Sym : SectionSyms[IS])
         OS << SymStr[Sym] << '\n';
     }




More information about the llvm-commits mailing list