Commit 7c7508a5 authored by François Degros's avatar François Degros Committed by Commit Bot

Made scoped_refptr copy constructors delegating constructors.

This removes a minor code duplication. AddRef is now only called in one place,
ie the constructor taking a raw pointer. Note that Release is already called in
one place only, ie the destructor.

Change-Id: I4fcd72ec0bcf4eb9269f593e171304223ef1dc0a
Reviewed-on: https://chromium-review.googlesource.com/835288Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: François Degros <fdegros@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525279}
parent 62a4fb9f
...@@ -159,28 +159,24 @@ class scoped_refptr { ...@@ -159,28 +159,24 @@ class scoped_refptr {
scoped_refptr() {} scoped_refptr() {}
// Constructs from raw pointer.
scoped_refptr(T* p) : ptr_(p) { scoped_refptr(T* p) : ptr_(p) {
if (ptr_) if (ptr_)
AddRef(ptr_); AddRef(ptr_);
} }
// Copy constructor. // Copy constructor. This is required in addition to the copy conversion
scoped_refptr(const scoped_refptr& r) : ptr_(r.ptr_) { // constructor below.
if (ptr_) scoped_refptr(const scoped_refptr& r) : scoped_refptr(r.ptr_) {}
AddRef(ptr_);
}
// Copy conversion constructor. // Copy conversion constructor.
template <typename U, template <typename U,
typename = typename std::enable_if< typename = typename std::enable_if<
std::is_convertible<U*, T*>::value>::type> std::is_convertible<U*, T*>::value>::type>
scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) { scoped_refptr(const scoped_refptr<U>& r) : scoped_refptr(r.ptr_) {}
if (ptr_)
AddRef(ptr_);
}
// Move constructor. This is required in addition to the conversion // Move constructor. This is required in addition to the move conversion
// constructor below in order for clang to warn about pessimizing moves. // constructor below.
scoped_refptr(scoped_refptr&& r) noexcept : ptr_(r.ptr_) { r.ptr_ = nullptr; } scoped_refptr(scoped_refptr&& r) noexcept : ptr_(r.ptr_) { r.ptr_ = nullptr; }
// Move conversion constructor. // Move conversion constructor.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment