<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Mar 2, 2014 at 9:12 AM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On 2014 Mar 2, at 01:51, Ahmed Charles <<a href="mailto:acharles@outlook.com">acharles@outlook.com</a>> wrote:<br>
<br>
> __==============================================================================<br>
<div class="">>><br>
>> --- llvm/trunk/include/llvm/ADT/OwningPtr.h (original)<br>
>> +++ llvm/trunk/include/llvm/ADT/OwningPtr.h Sat Mar  1 21:38:32 2014<br>
>> @@ -17,6 +17,7 @@<br>
>>  #include "llvm/Support/Compiler.h"<br>
>>  #include <cassert><br>
>>  #include <cstddef><br>
>> +#include <memory><br>
>><br>
>>  namespace llvm {<br>
>><br>
>> @@ -39,6 +40,17 @@ public:<br>
>>      return *this;<br>
>>    }<br>
>><br>
>> +  OwningPtr(std::unique_ptr<T> &&Other) : Ptr(Other.release()) {}<br>
>> +<br>
>> +  OwningPtr &operator=(std::unique_ptr<T> &&Other) {<br>
>><br>
>> Why an rvalue reference to a unique_ptr rather than passing the<br>
>> unique_ptr by value?<br>
><br>
> No particular reason, though I suppose it is one less write to memory if the optimizer can't remove it. I just didn't consider passing by value. Feel free to change, I don't have commit access yet.<br>
<br>
</div>An rvalue-reference makes sense here.  It makes it clear that OwningPtr<br>
is taking ownership from unique_ptr.</blockquote><div><br></div><div>Passing unique_ptr by value also makes that clear, and is the idiomatic way of passing ownership with unique_ptr.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In particular, its signature lines<br>
up with the standard signature for move assignment operators:<br>
<br>
   T &T::operator=(T &&);<br>
<br>
Matching the signature makes it obvious that it’s the same semantic<br>
operation.  (It’s also more efficient before compiler optimizations.)</blockquote></div><br></div><div class="gmail_extra">That's less efficient after compiler optimizations, in the case where the function isn't inlined for whatever reason. Efficiency before optimization is not worth optimizing for.</div>
</div>