Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Issue 2193443002: Adds move assignment operator to scoped_refptr (Closed)

Created:
4 years, 4 months ago by danilchap
Modified:
4 years, 4 months ago
CC:
webrtc-reviews_webrtc.org, tterriberry_mozilla.com
Base URL:
https://chromium.googlesource.com/external/webrtc.git@master
Target Ref:
refs/pending/heads/master
Project:
webrtc
Visibility:
Public.

Description

Adds move assignment operator to scoped_refptr Implementation borrowed from chromium. BUG=webrtc:5556 R=pthatcher@webrtc.org Committed: https://chromium.googlesource.com/external/webrtc/+/70cfc14af67ce2f85143fefa9ff28703445d0f43

Patch Set 1 #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+12 lines, -1 line) Patch
M webrtc/base/scoped_ref_ptr.h View 2 chunks +12 lines, -1 line 1 comment Download

Messages

Total messages: 10 (3 generated)
danilchap
move constructor is not enough, move operator= should be too.
4 years, 4 months ago (2016-07-28 16:32:53 UTC) #2
pthatcher1
lgtm
4 years, 4 months ago (2016-07-29 16:39:24 UTC) #3
commit-bot: I haz the power
Patchset 1 (id:??) landed as https://crrev.com/70cfc14af67ce2f85143fefa9ff28703445d0f43 Cr-Commit-Position: refs/heads/master@{#13577}
4 years, 4 months ago (2016-07-29 17:15:16 UTC) #6
danilchap
Committed patchset #1 (id:1) manually as 70cfc14af67ce2f85143fefa9ff28703445d0f43 (presubmit successful).
4 years, 4 months ago (2016-07-29 17:15:17 UTC) #7
Taylor Brandstetter
https://codereview.webrtc.org/2193443002/diff/1/webrtc/base/scoped_ref_ptr.h File webrtc/base/scoped_ref_ptr.h (right): https://codereview.webrtc.org/2193443002/diff/1/webrtc/base/scoped_ref_ptr.h#newcode138 webrtc/base/scoped_ref_ptr.h:138: scoped_refptr<T>(std::move(r)).swap(*this); I realize this uses the same method as ...
4 years, 4 months ago (2016-08-01 20:00:36 UTC) #8
danilchap
On 2016/08/01 20:00:36, Taylor Brandstetter wrote: > https://codereview.webrtc.org/2193443002/diff/1/webrtc/base/scoped_ref_ptr.h > File webrtc/base/scoped_ref_ptr.h (right): > > https://codereview.webrtc.org/2193443002/diff/1/webrtc/base/scoped_ref_ptr.h#newcode138 ...
4 years, 4 months ago (2016-08-02 09:24:06 UTC) #9
Taylor Brandstetter
4 years, 4 months ago (2016-08-02 17:18:25 UTC) #10
Message was sent while issue was closed.
On 2016/08/02 09:24:06, danilchap wrote:
> On 2016/08/01 20:00:36, Taylor Brandstetter wrote:
> > https://codereview.webrtc.org/2193443002/diff/1/webrtc/base/scoped_ref_ptr.h
> > File webrtc/base/scoped_ref_ptr.h (right):
> > 
> >
>
https://codereview.webrtc.org/2193443002/diff/1/webrtc/base/scoped_ref_ptr.h#...
> > webrtc/base/scoped_ref_ptr.h:138:
scoped_refptr<T>(std::move(r)).swap(*this);
> > I realize this uses the same method as Chromium's scoped_refptr, but do you
> know
> > why the std::move is used? Isn't `r` already movable, and so isn't this
> > std::move a no-op?
> 
> tl;dr without std::move copy constructor will be called to create temporary
> object
> 
> Yes and no.
> Yes r is movable because scoped_ref_ptr has movable constructor,
> yes std::move is a no-op because it is always a no-op (it is just a cast from
T
> to T&&)
> 
> No, 'r' is not movable. r parameter temporary means that at the end of the
> function r can end up in any valid state, but that doesn't mean it can be
> implicitly moved from in the middle of the function.
> No, std::move is not a no-op because it turns r from lvalue to xvalue. (See
1st
> rules for lvalue and xvalue at
> http://en.cppreference.com/w/cpp/language/value_category)
> 
> e.g. imagine this valid code:
> scoped_refptr<T>& operator=(scoped_refptr<T>&& r) {
>   scoped_refptr<T>(r).swap(*this);
>   r->DoSomethingElse();
> }
> 
> Here r is used after it was used create a temporary object, so can't be
allowed
> to be moved from in the 1st line.
> So 1st line need a hint when object will not be used later in the body of the
> function. That what std::move() does.

It's amazing I can use C++ for years and still not completely understand these
things. So a named rvalue reference is actually an lvalue; that's what I was
missing. Thanks for explaining.

Powered by Google App Engine
This is Rietveld 408576698