kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject incubator-kudu git commit: Support move constructor and assignment operator in scoped_refptr
Date Sat, 23 Jan 2016 02:38:05 GMT
Repository: incubator-kudu
Updated Branches:
  refs/heads/master 75d724451 -> 690f3594d


Support move constructor and assignment operator in scoped_refptr

This is a port over of 4c3de21a3dcdd9e27a770572350eeaa98cdb9e87 from
the chromium-base repository.

The port isn't 100% -- on their side they added a .Pass() to scoped_refptr.
However, I think in our case we should just use std::move() for this use case.

Change-Id: I339c9f6c3bfc0fcacd44aa53bdd75d723b9aab47
Reviewed-on: http://gerrit.cloudera.org:8080/1870
Tested-by: Todd Lipcon <todd@apache.org>
Reviewed-by: Dan Burkert <dan@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/690f3594
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/690f3594
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/690f3594

Branch: refs/heads/master
Commit: 690f3594db9f27bc77186a1216d20e5c83e4bb27
Parents: 75d7244
Author: Todd Lipcon <todd@apache.org>
Authored: Thu Jan 21 19:02:02 2016 -0800
Committer: Todd Lipcon <todd@apache.org>
Committed: Sat Jan 23 02:33:49 2016 +0000

----------------------------------------------------------------------
 src/kudu/gutil/ref_counted.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/690f3594/src/kudu/gutil/ref_counted.h
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/ref_counted.h b/src/kudu/gutil/ref_counted.h
index 875ddc5..8b6a553 100644
--- a/src/kudu/gutil/ref_counted.h
+++ b/src/kudu/gutil/ref_counted.h
@@ -245,6 +245,11 @@ class scoped_refptr {
       ptr_->AddRef();
   }
 
+  template <typename U>
+  scoped_refptr(scoped_refptr<U>&& r) : ptr_(r.get()) {
+    r.ptr_ = nullptr;
+  }
+
   ~scoped_refptr() {
     if (ptr_)
       ptr_->Release();
@@ -289,6 +294,17 @@ class scoped_refptr {
     return *this = r.get();
   }
 
+  scoped_refptr<T>& operator=(scoped_refptr<T>&& r) {
+    scoped_refptr<T>(r).swap(*this);
+    return *this;
+  }
+
+  template <typename U>
+  scoped_refptr<T>& operator=(scoped_refptr<U>&& r) {
+    scoped_refptr<T>(r).swap(*this);
+    return *this;
+  }
+
   void swap(T** pp) {
     T* p = ptr_;
     ptr_ = *pp;
@@ -307,6 +323,9 @@ class scoped_refptr {
 
  protected:
   T* ptr_;
+
+ private:
+  template <typename U> friend class scoped_refptr;
 };
 
 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without


Mime
View raw message