Skip to content

Commit f7189c4

Browse files
committed
Merge bitcoin/bitcoin#22941: wallet: refactor: inline functions {Read,Write}OrderPos
98cf19c wallet: refactor: avoid duplicate lookup on `mapValue["timesmart"]` (Sebastian Falbesoner) 973d8ba wallet: refactor: inline function WriteOrderPos() (Sebastian Falbesoner) 65ed198 wallet: refactor: inline function ReadOrderPos() (Sebastian Falbesoner) Pull request description: The functions `ReadOrderPos` and `WriteOrderPos` have been introduced in commit 9c7722b in 2012. Since accounts have been removed in #13825 (commit c9c32e6), they are only called at one place in `CWalletTx::{Serialize,Unserialize}` and thus can be directly inlined instead. Additionally, this PR aims to avoids duplicate lookups on the map `mapValue` (affects keys "n" and "timesmart"). ACKs for top commit: laanwj: Code review ACK 98cf19c achow101: Code Review ACK 98cf19c Tree-SHA512: 8af63c174c79e589bd713f04e8e40caba9f93ec2978c805427cac50d48049808a8c23ff5eea9ef589c9bd79fc66087f43ff5ab28e3cda51dd03f37c0164e2e4c
2 parents 6ef84e0 + 98cf19c commit f7189c4

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

src/wallet/transaction.h

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,6 @@
1919

2020
typedef std::map<std::string, std::string> mapValue_t;
2121

22-
23-
static inline void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue)
24-
{
25-
if (!mapValue.count("n"))
26-
{
27-
nOrderPos = -1; // TODO: calculate elsewhere
28-
return;
29-
}
30-
nOrderPos = atoi64(mapValue["n"]);
31-
}
32-
33-
34-
static inline void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
35-
{
36-
if (nOrderPos == -1)
37-
return;
38-
mapValue["n"] = ToString(nOrderPos);
39-
}
40-
4122
/** Legacy class used for deserializing vtxPrev for backwards compatibility.
4223
* vtxPrev was removed in commit 93a18a3650292afbb441a47d1fa1b94aeb0164e3,
4324
* but old wallet.dat files may still contain vtxPrev vectors of CMerkleTxs.
@@ -192,7 +173,9 @@ class CWalletTx
192173
mapValue_t mapValueCopy = mapValue;
193174

194175
mapValueCopy["fromaccount"] = "";
195-
WriteOrderPos(nOrderPos, mapValueCopy);
176+
if (nOrderPos != -1) {
177+
mapValueCopy["n"] = ToString(nOrderPos);
178+
}
196179
if (nTimeSmart) {
197180
mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart);
198181
}
@@ -232,8 +215,10 @@ class CWalletTx
232215
setConfirmed();
233216
}
234217

235-
ReadOrderPos(nOrderPos, mapValue);
236-
nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
218+
const auto it_op = mapValue.find("n");
219+
nOrderPos = (it_op != mapValue.end()) ? atoi64(it_op->second) : -1;
220+
const auto it_ts = mapValue.find("timesmart");
221+
nTimeSmart = (it_ts != mapValue.end()) ? static_cast<unsigned int>(atoi64(it_ts->second)) : 0;
237222

238223
mapValue.erase("fromaccount");
239224
mapValue.erase("spent");

0 commit comments

Comments
 (0)