Skip to content

Commit 7263424

Browse files
committed
Merge #16001: Give WalletModel::UnlockContext move semantics
0b09a57 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 bitcoin/bitcoin@0b09a57 jonasschnelli: utACK 0b09a57 jb55: utACK 0b09a57 Tree-SHA512: f827856586afd03666c2d9f50320776afb3dd511ac1bcd293b330f015acd1588551b163dccc97b1351301e3295f4c74d90e5754bcee89faeadf6437d7db165c8
2 parents 7110d45 + 0b09a57 commit 7263424

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/qt/walletmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ WalletModel::UnlockContext::~UnlockContext()
482482
}
483483
}
484484

485-
void WalletModel::UnlockContext::CopyFrom(const UnlockContext& rhs)
485+
void WalletModel::UnlockContext::CopyFrom(UnlockContext&& rhs)
486486
{
487487
// Transfer context; old object no longer relocks wallet
488488
*this = rhs;

src/qt/walletmodel.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,18 @@ class WalletModel : public QObject
194194

195195
bool isValid() const { return valid; }
196196

197-
// Copy operator and constructor transfer the context
198-
UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
199-
UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
197+
// Copy constructor is disabled.
198+
UnlockContext(const UnlockContext&) = delete;
199+
// Move operator and constructor transfer the context
200+
UnlockContext(UnlockContext&& obj) { CopyFrom(std::move(obj)); }
201+
UnlockContext& operator=(UnlockContext&& rhs) { CopyFrom(std::move(rhs)); return *this; }
200202
private:
201203
WalletModel *wallet;
202204
bool valid;
203205
mutable bool relock; // mutable, as it can be set to false by copying
204206

205-
void CopyFrom(const UnlockContext& rhs);
207+
UnlockContext& operator=(const UnlockContext&) = default;
208+
void CopyFrom(UnlockContext&& rhs);
206209
};
207210

208211
UnlockContext requestUnlock();

0 commit comments

Comments
 (0)