From 65ed198295e58cf1bc339aa17349b83490872f70 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Fri, 10 Sep 2021 16:17:03 +0200 Subject: wallet: refactor: inline function ReadOrderPos() Since accounts were removed in commit c9c32e6b844fc79467b7e24c6c916142a0d08484, this function is only called at one place and thus can be as well inlined. Also, avoid a duplicate lookup by using the find() method and dereference, instead of calling count() and operator[]. --- src/wallet/transaction.h | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/wallet/transaction.h b/src/wallet/transaction.h index 094221adf2..997b77c8db 100644 --- a/src/wallet/transaction.h +++ b/src/wallet/transaction.h @@ -20,17 +20,6 @@ typedef std::map mapValue_t; -static inline void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue) -{ - if (!mapValue.count("n")) - { - nOrderPos = -1; // TODO: calculate elsewhere - return; - } - nOrderPos = atoi64(mapValue["n"]); -} - - static inline void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue) { if (nOrderPos == -1) @@ -232,7 +221,8 @@ public: setConfirmed(); } - ReadOrderPos(nOrderPos, mapValue); + const auto it_op = mapValue.find("n"); + nOrderPos = (it_op != mapValue.end()) ? atoi64(it_op->second) : -1; nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0; mapValue.erase("fromaccount"); -- cgit v1.2.3 From 973d8ba93d0fa00bed4569287e32696300036ab8 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Fri, 10 Sep 2021 16:23:41 +0200 Subject: wallet: refactor: inline function WriteOrderPos() Since accounts were removed in commit c9c32e6b844fc79467b7e24c6c916142a0d08484, this function is only called at one place and thus can be as well inlined. --- src/wallet/transaction.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/wallet/transaction.h b/src/wallet/transaction.h index 997b77c8db..33cf667cd8 100644 --- a/src/wallet/transaction.h +++ b/src/wallet/transaction.h @@ -19,14 +19,6 @@ typedef std::map mapValue_t; - -static inline void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue) -{ - if (nOrderPos == -1) - return; - mapValue["n"] = ToString(nOrderPos); -} - /** Legacy class used for deserializing vtxPrev for backwards compatibility. * vtxPrev was removed in commit 93a18a3650292afbb441a47d1fa1b94aeb0164e3, * but old wallet.dat files may still contain vtxPrev vectors of CMerkleTxs. @@ -181,7 +173,9 @@ public: mapValue_t mapValueCopy = mapValue; mapValueCopy["fromaccount"] = ""; - WriteOrderPos(nOrderPos, mapValueCopy); + if (nOrderPos != -1) { + mapValueCopy["n"] = ToString(nOrderPos); + } if (nTimeSmart) { mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart); } -- cgit v1.2.3 From 98cf19ca32785c991628324c313e01349c2986af Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Fri, 10 Sep 2021 16:30:21 +0200 Subject: wallet: refactor: avoid duplicate lookup on `mapValue["timesmart"]` Also, use a named cast for converting the atoi64() result into an unsigned int type. --- src/wallet/transaction.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/transaction.h b/src/wallet/transaction.h index 33cf667cd8..0cd91b9ebe 100644 --- a/src/wallet/transaction.h +++ b/src/wallet/transaction.h @@ -217,7 +217,8 @@ public: const auto it_op = mapValue.find("n"); nOrderPos = (it_op != mapValue.end()) ? atoi64(it_op->second) : -1; - nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0; + const auto it_ts = mapValue.find("timesmart"); + nTimeSmart = (it_ts != mapValue.end()) ? static_cast(atoi64(it_ts->second)) : 0; mapValue.erase("fromaccount"); mapValue.erase("spent"); -- cgit v1.2.3