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 {
scoped_refptr() {}
// Constructs from raw pointer.
scoped_refptr(T* p) : ptr_(p) {
if (ptr_)
AddRef(ptr_);
}
// Copy constructor.
scoped_refptr(const scoped_refptr& r) : ptr_(r.ptr_) {
if (ptr_)
AddRef(ptr_);
}
// Copy constructor. This is required in addition to the copy conversion
// constructor below.
scoped_refptr(const scoped_refptr& r) : scoped_refptr(r.ptr_) {}
// Copy conversion constructor.
template <typename U,
typename = typename std::enable_if<
std::is_convertible<U*, T*>::value>::type>
scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) {
if (ptr_)
AddRef(ptr_);
}
scoped_refptr(const scoped_refptr<U>& r) : scoped_refptr(r.ptr_) {}
// Move constructor. This is required in addition to the conversion
// constructor below in order for clang to warn about pessimizing moves.
// Move constructor. This is required in addition to the move conversion
// constructor below.
scoped_refptr(scoped_refptr&& r) noexcept : ptr_(r.ptr_) { r.ptr_ = nullptr; }
// 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