No description provided.
Remove duplicate mapWallet lookups #12276
pull promag wants to merge 1 commits into bitcoin:master from promag:2018-01-mapwallet changing 1 files +6 −11-
promag commented at 4:30 PM on January 26, 2018: member
- promag renamed this:
[wallet] Remove duplicate mapWallet lookups
Remove duplicate mapWallet lookups
on Jan 26, 2018 - fanquake added the label Wallet on Jan 26, 2018
- MarcoFalke deleted a comment on Jan 27, 2018
-
in src/wallet/wallet.cpp:988 in 8f1243fa98 outdated
984 | @@ -988,9 +985,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose) 985 | bool CWallet::LoadToWallet(const CWalletTx& wtxIn) 986 | { 987 | uint256 hash = wtxIn.GetHash(); 988 | - 989 | - mapWallet[hash] = wtxIn; 990 | - CWalletTx& wtx = mapWallet[hash]; 991 | + CWalletTx& wtx = mapWallet[hash] = wtxIn;
laanwj commented at 9:15 AM on January 28, 2018:I think this isn't correct: C syntax
A = B = C = D = Xsets A,B,C,D to X.. So it assignswtxto a reference towtxIn, not to one tomapWallet[hash]as before.
promag commented at 9:50 AM on January 28, 2018:@laanwj the following:
#include <map> #include <string> #include <iostream> using namespace std; int main() { map<int,string> m; string s = "hello"; string& r = m[1] = s; r.append(" world"); cout << s << endl; cout << r << endl; cout << m[1] << endl; return 0; }gives:
hello hello world hello worldSo I think it's correct. I can make it more explicit and still avoid the 2nd lookup.
See http://en.cppreference.com/w/cpp/container/map/operator_at, returns the reference, and the right
=expression evaluates to that.
donaloconnor commented at 4:45 PM on January 28, 2018:Yes you are correct. Assignment happens from right to left. However I am not really a fan of the multiple assignment per line in this case since we are mixing reverence and value type assigmnents. It's a personal thing I guess but I usually like to separate such logic in multi-line as it helps with debugging etc. The compiler will optimize it anyway :-)
promag commented at 5:26 PM on January 28, 2018:Done.
laanwj commented at 1:13 PM on January 29, 2018:Good to know, thanks, didn't realize that, but yes it's better to avoid it to avoid confusion. The new formulation is more explicit.
MarcoFalke deleted a comment on Jan 28, 2018MarcoFalke deleted a comment on Jan 28, 2018[wallet] Remove duplicate mapWallet lookups 039425cf4fpromag force-pushed on Jan 28, 2018promag commented at 1:21 PM on January 29, 2018: memberHave to measure if it's of interest, but I suspect this improves the loading of big wallets a bit.
jonasschnelli commented at 6:55 PM on January 29, 2018: contributorutACK 039425cf4fab56ea0e42564849a15485afa582ae
donaloconnor commented at 9:24 PM on January 29, 2018: contributorutACK 039425c
laanwj commented at 9:16 AM on January 30, 2018: memberutACK 039425cf4fab56ea0e42564849a15485afa582ae
laanwj merged this on Jan 30, 2018laanwj closed this on Jan 30, 2018laanwj referenced this in commit 7936446268 on Jan 30, 2018PastaPastaPasta referenced this in commit 5604b3479a on Jan 17, 2020PastaPastaPasta referenced this in commit f8f176f3c7 on Jan 22, 2020PastaPastaPasta referenced this in commit 7622cb06fe on Jan 22, 2020PastaPastaPasta referenced this in commit 85d615a70e on Jan 29, 2020PastaPastaPasta referenced this in commit 325b2f7db1 on Jan 29, 2020PastaPastaPasta referenced this in commit a468059cf5 on Jan 29, 2020PastaPastaPasta referenced this in commit 8f2d96c88f on Jan 31, 2020ckti referenced this in commit 6d51bb6165 on Mar 28, 2021DrahtBot locked this on Sep 8, 2021ContributorsLabels
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 15:15 UTC
More mirrored repositories can be found on mirror.b10c.me