[PATCH] D139552: [NFC] Optimize vector usage in lld

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 8 19:15:02 PST 2022


int3 added inline comments.


================
Comment at: lld/COFF/Writer.cpp:521
     ArrayRef<coff_relocation> relocs = sc->getRelocs();
-    for (size_t j = 0, e = relocs.size(); j < e; ++j) {
-      const coff_relocation &rel = relocs[j];
+    for (const auto &rel : relocs) {
       Symbol *relocTarget = sc->file->getSymbol(rel.SymbolTableIndex);
----------------
codebase convention is to use explicit type instead of auto as long as it's not too ugly


================
Comment at: lld/ELF/InputFiles.cpp:1709
   std::string s = "_binary_" + mb.getBufferIdentifier().str();
-  for (size_t i = 0; i < s.size(); ++i)
-    if (!isAlnum(s[i]))
-      s[i] = '_';
+  for (char &i : s)
+    if (!isAlnum(i))
----------------
`c` seems like a better name for a char

also there's no need to take this by reference


================
Comment at: lld/ELF/MapFile.cpp:248
     Symbol *sym = kv.first;
-    SetVector<InputFile *> &files = kv.second;
-
----------------
let's keep this, seems like it was intentionally done to help readability


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139552/new/

https://reviews.llvm.org/D139552



More information about the llvm-commits mailing list