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
}
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;
}
// movable
Future(Future&&) noexcept;
- Future& operator=(Future&&);
+ Future& operator=(Future&&) noexcept;
// makeFuture
template <class F = 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;
}
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. */