Commit 4520e4b9 authored by Marshall Cline's avatar Marshall Cline Committed by Facebook Github Bot

Improve Promise move-ctor & move-assign

Summary:
- Promise move ctor: use folly::exchange()
- Promise move assign: make 33% faster, more eager to release memory, use folly::exchange()

Reviewed By: yfeldblum

Differential Revision: D7838311

fbshipit-source-id: 6d0ee8d3121ab703b3c54c72532f34d66bd4259c
parent 513eb37d
...@@ -36,15 +36,14 @@ Promise<T>::Promise() ...@@ -36,15 +36,14 @@ Promise<T>::Promise()
template <class T> template <class T>
Promise<T>::Promise(Promise<T>&& other) noexcept Promise<T>::Promise(Promise<T>&& other) noexcept
: retrieved_(other.retrieved_), core_(other.core_) { : retrieved_(exchange(other.retrieved_, false)),
other.core_ = nullptr; core_(exchange(other.core_, nullptr)) {}
other.retrieved_ = false;
}
template <class T> template <class T>
Promise<T>& Promise<T>::operator=(Promise<T>&& other) noexcept { Promise<T>& Promise<T>::operator=(Promise<T>&& other) noexcept {
std::swap(core_, other.core_); detach();
std::swap(retrieved_, other.retrieved_); retrieved_ = exchange(other.retrieved_, false);
core_ = exchange(other.core_, nullptr);
return *this; return *this;
} }
......
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