[llvm] r243616 - [LoopVer] Add missing std::move

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 08:01:43 PDT 2015


On Mon, Aug 10, 2015 at 4:54 AM, Joerg Sonnenberger via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> On Thu, Jul 30, 2015 at 04:21:13AM -0000, Adam Nemet wrote:
> > Author: anemet
> > Date: Wed Jul 29 23:21:13 2015
> > New Revision: 243616
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=243616&view=rev
> > Log:
> > [LoopVer] Add missing std::move
> >
> > The reason I was passing this vector by value in the constructor so that
> > I wouldn't have to copy when initializing the corresponding member but
> > then I forgot the std::move.
> >
> > The use-case is LoopDistribution which filters the checks then
> > std::moves it to LoopVersioning's constructor.  With this interface we
> > can avoid any copies.
>
> I don't understand this. Why is it preferable to have the copy
> constructor in the caller and move the result compared to using a
> reference and copy construct in place?
>

If the caller passes a temporary, this is two moves, zero copies. As in:

std::unique_ptr<int> u;
void func(std::unique_ptr<int> f) {
  u = std::move(f);
}
...
func(std::move(some_other_unique_ptr));

(just using a unique_ptr to demonstrate that this idiom allows callers to
choose between copies and moves (passing by const ref does not allow the
caller to choose - there will always be a copy (in the case of the
unique_ptr example, that means it's not possible, of course)))


>
> Joerg
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150810/6cb776a7/attachment.html>


More information about the llvm-commits mailing list