<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><div><br><div><div>On Mar 17, 2014, at 2:25 PM, Benjamin Kramer <<a href="mailto:benny.kra@gmail.com">benny.kra@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br>On 17.03.2014, at 22:18, Pete Cooper <<a href="mailto:peter_cooper@apple.com">peter_cooper@apple.com</a>> wrote:<br><br><blockquote type="cite"><br>On Mar 17, 2014, at 1:15 PM, Benjamin Kramer <<a href="mailto:benny.kra@gmail.com">benny.kra@gmail.com</a>> wrote:<br><br><blockquote type="cite"><br>On 17.03.2014, at 20:38, Chandler Carruth <<a href="mailto:chandlerc@google.com">chandlerc@google.com</a>> wrote:<br><br><blockquote type="cite"><br>On Mon, Mar 17, 2014 at 12:32 PM, Pete Cooper <<a href="mailto:peter_cooper@apple.com">peter_cooper@apple.com</a>> wrote:<br>I was worried about duplication, but actually that might be cleaner.  I’ll give that a try now.<br><br>If the duplication is a problem, factor that into a private helper function used by both?<br></blockquote><br>It can be written in two lines, not worth its own function.<br></blockquote>Agreed.<br><blockquote type="cite"><br>for (auto &Entry : this)<br>Entry.Destroy(Allocator);<br></blockquote>Thanks for this.  Its a nice small snippet.  I tweaked it to this:<br><br>   if (!empty()) {<br>     for (auto &Entry : *this)<br>       Entry.Destroy(Allocator);<br><br>However, this is still about 10% faster<br><br><br>   if (!empty()) {<br>     for (unsigned I = 0, E = NumBuckets; I != E; ++I) {<br>       StringMapEntryBase *&Bucket = TheTable[I];<br>       if (Bucket && Bucket != getTombstoneVal()) {<br>         static_cast<MapEntryTy*>(Bucket)->Destroy(Allocator);<br>       }<br>     }<br>   }<br><br>The problem is that iterator++ isn’t getting optimized out.  Actually neither is the whole loop I gave, but somehow it runs a bit quicker.  I think its failing to inline ++ as it shows up in the trace even on -O3.<br></blockquote><br>The latter loop gets eliminated by clang -O3 if I try it in the dtor of a simple StringMap<void*>. It's probably fine to use this more verbose form, eliminating the iterator loop is surprisingly hard, if possible at all.<br><br>- Ben</div></blockquote></div><br></div></div></body></html>