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
  1. promag commented at 4:30 PM on January 26, 2018: member

    No description provided.

  2. promag renamed this:
    [wallet] Remove duplicate mapWallet lookups
    Remove duplicate mapWallet lookups
    on Jan 26, 2018
  3. fanquake added the label Wallet on Jan 26, 2018
  4. MarcoFalke deleted a comment on Jan 27, 2018
  5. 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 = X sets A,B,C,D to X.. So it assigns wtx to a reference to wtxIn, not to one to mapWallet[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 world
    

    So 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.

  6. MarcoFalke deleted a comment on Jan 28, 2018
  7. MarcoFalke deleted a comment on Jan 28, 2018
  8. [wallet] Remove duplicate mapWallet lookups 039425cf4f
  9. promag force-pushed on Jan 28, 2018
  10. promag commented at 1:21 PM on January 29, 2018: member

    Have to measure if it's of interest, but I suspect this improves the loading of big wallets a bit.

  11. jonasschnelli commented at 6:55 PM on January 29, 2018: contributor

    utACK 039425cf4fab56ea0e42564849a15485afa582ae

  12. donaloconnor commented at 9:24 PM on January 29, 2018: contributor

    utACK 039425c

  13. laanwj commented at 9:16 AM on January 30, 2018: member

    utACK 039425cf4fab56ea0e42564849a15485afa582ae

  14. laanwj merged this on Jan 30, 2018
  15. laanwj closed this on Jan 30, 2018

  16. laanwj referenced this in commit 7936446268 on Jan 30, 2018
  17. PastaPastaPasta referenced this in commit 5604b3479a on Jan 17, 2020
  18. PastaPastaPasta referenced this in commit f8f176f3c7 on Jan 22, 2020
  19. PastaPastaPasta referenced this in commit 7622cb06fe on Jan 22, 2020
  20. PastaPastaPasta referenced this in commit 85d615a70e on Jan 29, 2020
  21. PastaPastaPasta referenced this in commit 325b2f7db1 on Jan 29, 2020
  22. PastaPastaPasta referenced this in commit a468059cf5 on Jan 29, 2020
  23. PastaPastaPasta referenced this in commit 8f2d96c88f on Jan 31, 2020
  24. ckti referenced this in commit 6d51bb6165 on Mar 28, 2021
  25. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

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

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me