<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jul 27, 2015 at 4:18 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span class=""><div dir="ltr">On Mon, Jul 27, 2015 at 2:02 PM Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br></div></span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><div dir="ltr"><div>On Mon, Jul 27, 2015 at 12:01 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br></div></div></span><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><span class=""><br>
> On 2015-Jul-25, at 17:50, Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br>
><br>
> Author: ruiu<br>
> Date: Sat Jul 25 19:50:15 2015<br>
> New Revision: 243232<br>
><br></span>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D243232-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=A7YEbZn5UiSjeArc6rLNc6OXlfY7Hm0OXfSQWGYHAns&s=wmdRPI5Lb9TNc_6lTBnZH0eo6CyF0IJSE6TQ7CrgwlU&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=243232&view=rev</a><span class=""><br>
> Log:<br>
> ELF2: Avoid calling std::sort to make output deterministic.<br>
<br>
</span></span><span class="">Using `std::stable_sort` should also make it deterministic.  Is that<br>
better than switching to a `std::map`?<br></span></blockquote><div><br></div></div></div></div><span class=""><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Yeah, I think the new code is slightly more readable than the previous one. At least it's shorter than before.</div></div></div></div></span></blockquote><div><br></div><div><br></div><div>"Yeah" doesn't seem to agree with the rest of your email, so I'm left confused.</div><div><br></div><div>Why wouldn't switching to std::stable_sort be better?</div><div><br></div><div>std::map is horribly slow in essentially every way, and so I struggle to believe it is the best tool for the job even if the code using it is very compact.</div></div></div></blockquote><div><br></div><div>std::stable_sort would actually be slower than the new code. What we are doing here is bin chunks into a few sections, so putting everything into one array and stable-sorting them and scanning them again doesn't make much sense. We used std::stable_sort in COFF before but I removed that in r239292 for that reason.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br>
><br>
> Modified:<br>
>    lld/trunk/ELF/Writer.cpp<br>
><br>
> Modified: lld/trunk/ELF/Writer.cpp<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Writer.cpp-3Frev-3D243232-26r1-3D243231-26r2-3D243232-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=A7YEbZn5UiSjeArc6rLNc6OXlfY7Hm0OXfSQWGYHAns&s=pRVul_ct6AiIzUBKOQnvAVJ__uAbRsd-pdfkjBz9dco&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=243232&r1=243231&r2=243232&view=diff</a><div><div class="h5"><br>
> ==============================================================================<br>
> --- lld/trunk/ELF/Writer.cpp (original)<br>
> +++ lld/trunk/ELF/Writer.cpp Sat Jul 25 19:50:15 2015<br>
> @@ -10,6 +10,7 @@<br>
> #include "Writer.h"<br>
> #include "Chunks.h"<br>
> #include "Driver.h"<br>
> +#include <map><br>
><br>
> using namespace llvm;<br>
> using namespace llvm::ELF;<br>
> @@ -58,24 +59,14 @@ void OutputSection::addChunk(Chunk *C) {<br>
>   Header.sh_size = Off;<br>
> }<br>
><br>
> -static int compare(const Chunk *A, const Chunk *B) {<br>
> -  return A->getSectionName() < B->getSectionName();<br>
> -}<br>
> -<br>
> // Create output section objects and add them to OutputSections.<br>
> template <class ELFT> void Writer<ELFT>::createSections() {<br>
> -  std::vector<Chunk *> Chunks = Symtab->getChunks();<br>
> -  if (Chunks.empty())<br>
> -    return;<br>
> -  std::sort(Chunks.begin(), Chunks.end(), compare);<br>
> -<br>
> -  Chunk *Prev = nullptr;<br>
> -  OutputSection *Sec = nullptr;<br>
> -  for (Chunk *C : Chunks) {<br>
> -    if (Prev == nullptr || Prev->getSectionName() != C->getSectionName()) {<br>
> +  std::map<StringRef, OutputSection *> Map;<br>
> +  for (Chunk *C : Symtab->getChunks()) {<br>
> +    OutputSection *&Sec = Map[C->getSectionName()];<br>
> +    if (!Sec) {<br>
>       Sec = new (CAlloc.Allocate()) OutputSection(C->getSectionName());<br>
>       OutputSections.push_back(Sec);<br>
> -      Prev = C;<br>
>     }<br>
>     Sec->addChunk(C);<br>
>   }<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br>
</div></div></div></div></blockquote></div></div></div><div><div class="h5">
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div></div>
</blockquote></div><br></div></div>