mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 01:33:20 +02:00
refactor: Avoid copying util::Result values
Copying util::Result values is less efficient than moving them because they allocate memory and contain strings. Also this is needed to avoid compile errors in https://github.com/bitcoin/bitcoin/pull/25722 which adds a std::unique_ptr member to util::Result which implicity disables copying.
This commit is contained in:
@@ -39,6 +39,9 @@ private:
|
||||
|
||||
std::variant<bilingual_str, T> m_variant;
|
||||
|
||||
//! Disallow copy constructor, require Result to be moved for efficiency.
|
||||
Result(const Result&) = delete;
|
||||
|
||||
//! Disallow operator= to avoid confusion in the future when the Result
|
||||
//! class gains support for richer error reporting, and callers should have
|
||||
//! ability to set a new result value without clearing existing error
|
||||
@@ -53,7 +56,6 @@ public:
|
||||
Result() : m_variant{std::in_place_index_t<1>{}, std::monostate{}} {} // constructor for void
|
||||
Result(T obj) : m_variant{std::in_place_index_t<1>{}, std::move(obj)} {}
|
||||
Result(Error error) : m_variant{std::in_place_index_t<0>{}, std::move(error.message)} {}
|
||||
Result(const Result&) = default;
|
||||
Result(Result&&) = default;
|
||||
~Result() = default;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user