<div dir="ltr">Out of curiosity - what was the motivation for this change? I'd expect that copy would be faster than repeated push_back (though maybe LLVM can optimize it to match)<br><br><div class="gmail_quote"><div dir="ltr">On Tue, Apr 3, 2018 at 1:00 PM Rui Ueyama via Phabricator via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">ruiu created this revision.<br>
ruiu added a reviewer: pcc.<br>
Herald added subscribers: arichardson, emaste.<br>
Herald added a reviewer: espindola.<br>
<br>
Instead of using std::copy, clear the vector first and add new elements. NFC.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D45227" rel="noreferrer" target="_blank">https://reviews.llvm.org/D45227</a><br>
<br>
Files:<br>
  lld/ELF/Writer.cpp<br>
<br>
<br>
Index: lld/ELF/Writer.cpp<br>
===================================================================<br>
--- lld/ELF/Writer.cpp<br>
+++ lld/ELF/Writer.cpp<br>
@@ -1137,24 +1137,23 @@<br>
   // of the second block of cold code can call the hot code without a thunk. So<br>
   // we effectively double the amount of code that could potentially call into<br>
   // the hot code without a thunk.<br>
-  size_t UnorderedInsPt = 0;<br>
+  size_t InsPt = 0;<br>
   if (Target->ThunkSectionSpacing && !OrderedSections.empty()) {<br>
     uint64_t UnorderedPos = 0;<br>
-    for (; UnorderedInsPt != UnorderedSections.size(); ++UnorderedInsPt) {<br>
-      UnorderedPos += UnorderedSections[UnorderedInsPt]->getSize();<br>
+    for (; InsPt != UnorderedSections.size(); ++InsPt) {<br>
+      UnorderedPos += UnorderedSections[InsPt]->getSize();<br>
       if (UnorderedPos > UnorderedSize / 2)<br>
         break;<br>
     }<br>
   }<br>
<br>
-  std::copy(UnorderedSections.begin(),<br>
-            UnorderedSections.begin() + UnorderedInsPt, ISD->Sections.begin());<br>
-  std::vector<InputSection *>::iterator SectionsPos =<br>
-      ISD->Sections.begin() + UnorderedInsPt;<br>
+  ISD->Sections.clear();<br>
+  for (InputSection *IS : makeArrayRef(UnorderedSections).slice(0, InsPt))<br>
+    ISD->Sections.push_back(IS);<br>
   for (std::pair<InputSection *, int> P : OrderedSections)<br>
-    *SectionsPos++ = P.first;<br>
-  std::copy(UnorderedSections.begin() + UnorderedInsPt, UnorderedSections.end(),<br>
-            SectionsPos);<br>
+    ISD->Sections.push_back(P.first);<br>
+  for (InputSection *IS : makeArrayRef(UnorderedSections).slice(InsPt))<br>
+    ISD->Sections.push_back(IS);<br>
 }<br>
<br>
 static void sortSection(OutputSection *Sec,<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>