<div dir="ltr">Ah, so ArrayRef is strictly preferable only to const SmallVectorImpl&. Makes sense, thanks!</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 3, 2019 at 5:42 PM David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The documentation might be specifically calling out the non-const<br>
SmallVector ref case. That would be the case wheer you want to modify<br>
the vector or its contents.<br>
<br>
If you don't want to do any mutation and the container can't change<br>
underneath you (eg: nothing happening inside the function might cause,<br>
indirectly, the vector to be resized, etc) then ArrayRef is probably<br>
the right tool.<br>
<br>
If you want to modify the existing elements of the container (&<br>
similarly, the vector won't be resized, etc) - MutableArrayRef would<br>
be suitable.<br>
<br>
If you need to be able to add or remove elements from the vector, or<br>
reflect changes due to indirect modifications - SmallVectorImpl& would<br>
be the most suitable.<br>
<br>
On Fri, May 3, 2019 at 9:39 AM Russell Wallace via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> It is suggested in the documentation that if you would have declared a function parameter as SmallVector<Foo,N>&, it is better to instead declare it as SmallVectorImpl<Foo>&.<br>
><br>
> This makes sense, but it seems to me that it is better still to declare it as ArrayRef<Foo>; a quick test suggests it compiles to the same (highly efficient) code, and adds a bit more flexibility in case e.g. you someday want to pass a std::vector.<br>
><br>
> By that logic, there is never any reason to take a SmallVectorImpl, because ArrayRef is strictly better. Am I missing anything?<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>