<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 25, 2016, at 9:01 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Mar 25, 2016 at 8:59 AM, Mehdi Amini <span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">It would, it is just hard to write :)<div class=""><br class=""></div><div class="">Usually the pattern is that the client side has two statements: 1 for the allocation and 1 for the insertion. So you can get the number of buckets between the allocation and the insertion, and verify that it is the same after. Here everything happens in the constructor...</div></div></blockquote><div class=""><br class=""></div><div class="">I was thinking you could count the moves - if the initial size is set to small, you should see a reallocation during the init list ctor execution, and you should see a bunch of move constructions. With the size set correctly you shouldn't see any move constructions, only copy constructions (in either case you should see exactly as many copy constructions as there are elements in the init list).<br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>OK, but we first need to figure the move-elision thing :(</div><div><br class=""></div><div>So when we start with (StringMap)Map.insert(std::make_pair(Twine(i).str(), CountCtorCopyAndMove()));</div><div><br class=""></div><div>We have a first potential move to create the pair. </div><div>Then we can have a second move when the pair is moved as a parameter to insert().</div><div><br class=""></div><div>std::pair<iterator, bool> insert(std::pair<StringRef, ValueTy> KV) {</div><div>  return emplace_second(KV.first, std::move(KV.second));<br class="">}<br class=""><br class=""></div><div>Here we have an explicit move (can it be legally elided or is it forced?).</div><div><br class=""></div><div>In emplace_second we forward (another potential move):</div><div><br class=""></div><div>  template <typename... ArgsTy><br class="">  std::pair<iterator, bool> emplace_second(StringRef Key, ArgsTy &&... Args) {<br class="">....</div><div>    Bucket = MapEntryTy::Create(Key, Allocator, std::forward<ArgsTy>(Args)...);<br class=""><br class=""></div><div><br class=""></div><div>In `create`, we forward again (yet another potential move?):</div><div><br class=""></div><div>  template <typename AllocatorTy, typename... InitTy><br class="">  static StringMapEntry *Create(StringRef Key, AllocatorTy &Allocator,<br class="">                                InitTy &&... InitVals) {<br class="">....</div><div>    // Construct the value.<br class="">    new (NewItem) StringMapEntry(KeyLength, std::forward<InitTy>(InitVals)...);<br class=""><br class=""></div><div>Finally the last move is when we construct the value in the entry:</div><div><br class=""></div><div>  StringMapEntry(unsigned strLen, InitTy &&... InitVals)<br class="">      : StringMapEntryBase(strLen), second(std::forward<InitTy>(InitVals)...) {}<br class=""><br class=""></div><div><br class=""></div><div><br class=""></div><div>So a potential of 6 moves, but clang will perform only 3, but MSVC will perform 4.</div><div><br class=""></div><div><br class=""></div><div>-- </div><div>Mehdi</div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class="">At least that's how I'm picturing it.<br class=""><br class="">- Dave</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><span class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">-- </div><div class="">Mehdi</div></font></span><div class=""><div class="h5"><div class=""><br class=""></div><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Mar 25, 2016, at 7:11 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank" class="">dblaikie@gmail.com</a>> wrote:</div><br class=""><div class=""><p dir="ltr" class="">Worth a test?</p>
<div class="gmail_quote">On Mar 24, 2016 11:02 PM, "Mehdi Amini via llvm-commits" <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>> wrote:<br type="attribution" class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mehdi_amini<br class="">
Date: Fri Mar 25 00:57:47 2016<br class="">
New Revision: 264383<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=264383&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=264383&view=rev</a><br class="">
Log:<br class="">
StringMap: reserve appropriate size when initializing from an initializer list<br class="">
<br class="">
From: Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>><br class="">
<br class="">
Modified:<br class="">
    llvm/trunk/include/llvm/ADT/StringMap.h<br class="">
<br class="">
Modified: llvm/trunk/include/llvm/ADT/StringMap.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=264383&r1=264382&r2=264383&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=264383&r1=264382&r2=264383&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)<br class="">
+++ llvm/trunk/include/llvm/ADT/StringMap.h Fri Mar 25 00:57:47 2016<br class="">
@@ -233,7 +233,7 @@ public:<br class="">
       Allocator(A) {}<br class="">
<br class="">
   StringMap(std::initializer_list<std::pair<StringRef, ValueTy>> List)<br class="">
-      : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {<br class="">
+      : StringMapImpl(List.size(), static_cast<unsigned>(sizeof(MapEntryTy))) {<br class="">
     for (const auto &P : List) {<br class="">
       insert(P);<br class="">
     }<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></div></div></div></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></body></html>