<div dir="ltr"><div><div>Not sure if this is "change clang itself" or "make clang do this transform". <br><br></div>On the "change clang itself to use emplace_back, the general principle is that you should use push_back whenever "feasible", and emplace_back if there is a specific reason to use that - for example non-copyable objects, or very large objects that take significant to copy construct.<br><br></div><div>If it's "make clang do this", I think it would be interesting to see if this can be detected and converted and how much improvement that gives for average cases - and if there are cases where it's detrimental? Some benchmarks to show the difference would be nice.<br><br>--<br></div><div>Mats<br></div><div><br></div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 29 April 2016 at 16:19, David Blaikie via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</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">Transformation as in clang-tidy? Or as in optimization in Clang? I doubt the latter, but could imagine the former. I'm not sure if it's a universally preferred transformation, though (but that's one of the benefits of clang-tidy, it doesn't have to be)</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 28, 2016 at 7:00 PM, Vedant Kumar via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
It's common to see code which does this:<br>
<br>
  (1) V.push_back(T(args, ...));<br>
<br>
When it could do this instead:<br>
<br>
  (2) V.emplace_back(args, ...);<br>
<br>
IIUC, the copy constructor for T is never called in case (2).<br>
<br>
Would it be possible/worthwhile/correctness-preserving to perform this transformation in clang? Based on a cursory grep it doesn't seem like we do this today, but I could've missed something.<br>
<br>
thanks<br>
vedant<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>