Option: Simplify release_value

This avoids copying + we don't need to destroy the item if we move it, since it either gets emptied by moving it or doesn't have anything to destroy.
This commit is contained in:
apio 2022-12-16 18:13:40 +01:00
parent 19a4e2ab58
commit 32c8869973
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -50,10 +50,8 @@ template <typename T> class Option
T release_value() T release_value()
{ {
expect(has_value(), "Option::release_value called on an empty Option"); expect(has_value(), "Option::release_value called on an empty Option");
T item = m_storage.fetch_reference();
m_has_value = false; m_has_value = false;
m_storage.destroy(); return move(m_storage.fetch_reference());
return move(item);
} }
T value_or(const T& other) const T value_or(const T& other) const