From efecbe5fbf3cedbb7b22431a8764469d064a251f Mon Sep 17 00:00:00 2001 From: Hannes Roth Date: Wed, 18 Mar 2015 10:29:19 -0700 Subject: [PATCH] (Wangle) Clean up move constructors Summary: I thought this might fix #6120972. But it doesn't. Still a bit of a cleanup in my opinion. Test Plan: Run all the tests? Reviewed By: hans@fb.com Subscribers: trunkagent, folly-diffs@, jsedgwick, yfeldblum FB internal diff: D1907259 Signature: t1:1907259:1426613567:9e33fe7e9e8a36ba006d4aee604086a56f128893 --- folly/futures/Future-inl.h | 6 +++--- folly/futures/Future.h | 2 +- folly/futures/Promise-inl.h | 8 +++++--- folly/futures/Promise.h | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index 077a633e..2e942303 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -33,12 +33,12 @@ namespace detail { } template -Future::Future(Future&& other) noexcept : core_(nullptr) { - *this = std::move(other); +Future::Future(Future&& other) noexcept : core_(other.core_) { + other.core_ = nullptr; } template -Future& Future::operator=(Future&& other) { +Future& Future::operator=(Future&& other) noexcept { std::swap(core_, other.core_); return *this; } diff --git a/folly/futures/Future.h b/folly/futures/Future.h index 10bdc45a..38b3072e 100644 --- a/folly/futures/Future.h +++ b/folly/futures/Future.h @@ -193,7 +193,7 @@ class Future { // movable Future(Future&&) noexcept; - Future& operator=(Future&&); + Future& operator=(Future&&) noexcept; // makeFuture template diff --git a/folly/futures/Promise-inl.h b/folly/futures/Promise-inl.h index f38ee60d..b57e952f 100644 --- a/folly/futures/Promise-inl.h +++ b/folly/futures/Promise-inl.h @@ -29,12 +29,14 @@ Promise::Promise() : retrieved_(false), core_(new detail::Core()) {} template -Promise::Promise(Promise&& other) : core_(nullptr) { - *this = std::move(other); +Promise::Promise(Promise&& other) noexcept + : retrieved_(other.retrieved_), core_(other.core_) { + other.core_ = nullptr; + other.retrieved_ = false; } template -Promise& Promise::operator=(Promise&& other) { +Promise& Promise::operator=(Promise&& other) noexcept { std::swap(core_, other.core_); std::swap(retrieved_, other.retrieved_); return *this; diff --git a/folly/futures/Promise.h b/folly/futures/Promise.h index 7d1eafc0..a38d6f1c 100644 --- a/folly/futures/Promise.h +++ b/folly/futures/Promise.h @@ -36,8 +36,8 @@ public: Promise& operator=(Promise const&) = delete; // movable - Promise(Promise&&); - Promise& operator=(Promise&&); + Promise(Promise&&) noexcept; + Promise& operator=(Promise&&) noexcept; /** Return a Future tied to the shared core state. This can be called only once, thereafter Future already retrieved exception will be raised. */ -- 2.34.1