[lld] r277653 - Create only one vector instead of two.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 3 14:12:10 PDT 2016


Author: ruiu
Date: Wed Aug  3 16:12:09 2016
New Revision: 277653

URL: http://llvm.org/viewvc/llvm-project?rev=277653&view=rev
Log:
Create only one vector instead of two.

In this for-loop, we append elements from one vector to another,
which is a bit inefficient.

Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=277653&r1=277652&r2=277653&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Aug  3 16:12:09 2016
@@ -160,20 +160,22 @@ void LinkerScript<ELFT>::createSections(
   OutputSections = Out;
 
   for (auto &P : getSectionMap()) {
-    std::vector<InputSectionBase<ELFT> *> Sections;
     StringRef OutputName = P.first;
-    const InputSectionDescription *I = P.second;
-    for (InputSectionBase<ELFT> *S : getInputSections(I)) {
-      if (OutputName == "/DISCARD/") {
+    const InputSectionDescription *Cmd = P.second;
+    std::vector<InputSectionBase<ELFT> *> Sections = getInputSections(Cmd);
+
+    if (OutputName == "/DISCARD/") {
+      for (InputSectionBase<ELFT> *S : Sections) {
         S->Live = false;
         reportDiscarded(S);
-        continue;
       }
-      Sections.push_back(S);
+      continue;
     }
-    if (I->Sort != SortKind::None)
+
+    if (Cmd->Sort != SortKind::None)
       std::stable_sort(Sections.begin(), Sections.end(),
-                       SectionsSorter<ELFT>(I->Sort));
+                       SectionsSorter<ELFT>(Cmd->Sort));
+
     for (InputSectionBase<ELFT> *S : Sections)
       addSection(Factory, *Out, S, OutputName);
   }




More information about the llvm-commits mailing list