<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 30, 2020 at 9:02 PM Michael Kruse via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Am Mo., 30. Nov. 2020 um 19:34 Uhr schrieb Duncan P. N. Exon Smith<br>
<<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>>:r<T, 0> has a number of benefits that make it<br>
better in practice than std::vector, at least for LLVM code:<br>
> - Interoperates with the pervasively used SmallVectorImpl<T>.<br>
> - No exception guarantees, and thus none of the related, harmful pessimizations (std::vector::resize will do expensive copies instead of cheap moves in some cases, last I checked).<br>
> - Customizations for using memcpy more often.<br>
> - Smaller by a pointer for most `T` (64-bit pointers).<br>
<br>
The LLVM project also hosts libc++, shouldn't we dogfood our own<br>
implementations?<br></blockquote><div><br></div><div>std::vector is limited by what the standard allows though. In particular in terms of exception safety (IIRC you can't use -fnoexception to change the behavior like moving instead of copying in general).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
2 and 3 should be optimizations possible in the STL. I disagree that<br>
SmallVectorImpl is pervasively used. </blockquote><div><br></div><div>Any method that accepts a container and will do something like "push_back" on it has to either take SmallVectorImpl or be templated to accept std::vector and SmallVector.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">The normal use case is a function<br>
parameter where the caller creates a SmallVector just to pass it, and<br>
can continue to do so with zero inline elements even if in other<br>
places we use std::vector.<br>
<br>
Michael<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>