<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jul 27, 2015 at 5:00 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On 2015-Jul-27, at 16:37, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
><br>
> On Mon, Jul 27, 2015 at 4:18 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com">chandlerc@google.com</a>> wrote:<br>
> On Mon, Jul 27, 2015 at 2:02 PM Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
> On Mon, Jul 27, 2015 at 12:01 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>> wrote:<br>
<span class="">><br>
> > On 2015-Jul-25, at 17:50, Rui Ueyama <<a href="mailto:ruiu@google.com">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=FOtRwwoh3QIw8a6gZydR2EQSzxrRmt69FZRo1g0Fr5w&s=h5zNQjyfdIEeq-OxQM3_nOht4rKKekP5tX19uWBQ1r8&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=243232&view=rev</a><br>
<span class="">> > Log:<br>
> > ELF2: Avoid calling std::sort to make output deterministic.<br>
><br>
> Using `std::stable_sort` should also make it deterministic.  Is that<br>
> better than switching to a `std::map`?<br>
><br>
> Yeah, I think the new code is slightly more readable than the previous one. At least it's shorter than before.<br>
><br>
><br>
> "Yeah" doesn't seem to agree with the rest of your email, so I'm left confused.<br>
><br>
> Why wouldn't switching to std::stable_sort be better?<br>
><br>
> 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.<br>
><br>
> 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>
<br>
</span>Looking again, you're just using `Map` as a cache here, right?  If<br>
you're not iterating over the map, you can probably skip the<br>
red-black tree by using a (Small?)DenseMap.<br></blockquote><div><br></div><div>Yes, we can do that. Use of std::map was just my negligence. I'll replace them with a DenseMap.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
><br>
><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=FOtRwwoh3QIw8a6gZydR2EQSzxrRmt69FZRo1g0Fr5w&s=x6VrR6VrWew9p_jOskeajCeCVplqz4dLNLEJzxPXuRc&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><br>
<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>
</div></div>> > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<span class="">> > <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>
> _______________________________________________<br>
> llvm-commits mailing list<br>
</span>> <a href="mailto:llvm-commits@cs.uiuc.edu">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>
<br>
</blockquote></div><br></div></div>