Commit 0fd618d4 authored by Hannes Roth's avatar Hannes Roth Committed by Alecs King

(Wangle) Clean up move constructors

Summary:
These were doing more assignments than necessary.
1) We don't need to set `core_` to `nullptr` and then immediately
overwrite it with `other.core_`.
2) Don't need to swap the booleans (this was actually an unitialized
memory access).

Test Plan: Ran all the tests.

Reviewed By: hans@fb.com

Subscribers: trunkagent, folly-diffs@, jsedgwick, yfeldblum

FB internal diff: D1852386

Signature: t1:1852386:1424375154:25997209e76ccd16169125597e868932a5143ffb
parent 37dd79a6
......@@ -32,13 +32,14 @@ namespace detail {
}
template <class T>
Future<T>::Future(Future<T>&& other) noexcept : core_(nullptr) {
*this = std::move(other);
Future<T>::Future(Future<T>&& other) noexcept : core_(other.core_) {
other.core_ = nullptr;
}
template <class T>
Future<T>& Future<T>::operator=(Future<T>&& other) {
std::swap(core_, other.core_);
Future<T>& Future<T>::operator=(Future<T>&& other) noexcept {
core_ = other.core_;
other.core_ = nullptr;
return *this;
}
......
......@@ -192,7 +192,7 @@ class Future {
// movable
Future(Future&&) noexcept;
Future& operator=(Future&&);
Future& operator=(Future&&) noexcept;
// makeFuture
template <class F = T>
......
......@@ -29,14 +29,16 @@ Promise<T>::Promise() : retrieved_(false), core_(new detail::Core<T>())
{}
template <class T>
Promise<T>::Promise(Promise<T>&& other) : core_(nullptr) {
*this = std::move(other);
Promise<T>::Promise(Promise<T>&& other) noexcept
: retrieved_(other.retrieved_), core_(other.core_) {
other.core_ = nullptr;
}
template <class T>
Promise<T>& Promise<T>::operator=(Promise<T>&& other) {
std::swap(core_, other.core_);
std::swap(retrieved_, other.retrieved_);
Promise<T>& Promise<T>::operator=(Promise<T>&& other) noexcept {
retrieved_ = other.retrieved_;
core_ = other.core_;
other.core_ = nullptr;
return *this;
}
......
......@@ -36,8 +36,8 @@ public:
Promise& operator=(Promise const&) = delete;
// movable
Promise(Promise<T>&&);
Promise& operator=(Promise<T>&&);
Promise(Promise<T>&&) noexcept;
Promise& operator=(Promise<T>&&) noexcept;
/** Return a Future tied to the shared core state. This can be called only
once, thereafter Future already retrieved exception will be raised. */
......
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