mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-22 14:35:07 +02:00
Merge #16001: Give WalletModel::UnlockContext move semantics
0b09a57ae Give WalletModel::UnlockContext move semantics (Pieter Wuille)
Pull request description:
WalletModel::UnlockContext seems to implement "move upon copy" semantics; with C++11 this can be done more safely using move semantics (making attempts to actually copy fail instead).
Not a big deal if this isn't worth review time.
ACKs for commit 0b09a5:
Empact:
utACK 0b09a57aec
jonasschnelli:
utACK 0b09a57aec4c56712711585a4314d73d4d9b6877
jb55:
utACK 0b09a57aec4c56712711585a4314d73d4d9b6877
Tree-SHA512: f827856586afd03666c2d9f50320776afb3dd511ac1bcd293b330f015acd1588551b163dccc97b1351301e3295f4c74d90e5754bcee89faeadf6437d7db165c8
This commit is contained in:
commit
7263424458
@ -482,7 +482,7 @@ WalletModel::UnlockContext::~UnlockContext()
|
||||
}
|
||||
}
|
||||
|
||||
void WalletModel::UnlockContext::CopyFrom(const UnlockContext& rhs)
|
||||
void WalletModel::UnlockContext::CopyFrom(UnlockContext&& rhs)
|
||||
{
|
||||
// Transfer context; old object no longer relocks wallet
|
||||
*this = rhs;
|
||||
|
@ -194,15 +194,18 @@ public:
|
||||
|
||||
bool isValid() const { return valid; }
|
||||
|
||||
// Copy operator and constructor transfer the context
|
||||
UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
|
||||
UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
|
||||
// Copy constructor is disabled.
|
||||
UnlockContext(const UnlockContext&) = delete;
|
||||
// Move operator and constructor transfer the context
|
||||
UnlockContext(UnlockContext&& obj) { CopyFrom(std::move(obj)); }
|
||||
UnlockContext& operator=(UnlockContext&& rhs) { CopyFrom(std::move(rhs)); return *this; }
|
||||
private:
|
||||
WalletModel *wallet;
|
||||
bool valid;
|
||||
mutable bool relock; // mutable, as it can be set to false by copying
|
||||
|
||||
void CopyFrom(const UnlockContext& rhs);
|
||||
UnlockContext& operator=(const UnlockContext&) = default;
|
||||
void CopyFrom(UnlockContext&& rhs);
|
||||
};
|
||||
|
||||
UnlockContext requestUnlock();
|
||||
|
Loading…
x
Reference in New Issue
Block a user