Fix more constness violations in serialization code #12683

pull sipa wants to merge 2 commits into bitcoin:master from sipa:201803_moreser changing 10 files +30 −56
  1. sipa commented at 0:18 am on March 14, 2018: member

    This is another fragment of improvements from #10785.

    The current serialization code does not support serializing/deserializing from/to temporaries (like s >> CFlatData(script)). As a result, there are many invocations of the REF macro which in addition to changing the reference type also changes the constness. This is unnecessary in C++11 as we can use rvalue references now instead.

    The first commit is an extra simplification we can make that removes the duplication of code between READWRITE and READWRITEMANY (and related functions).

  2. Merge READWRITEMANY into READWRITE 2761bca997
  3. Support deserializing into temporaries
    Currently, the READWRITE macro cannot be passed any non-const temporaries, as
    the SerReadWrite function only accepts lvalue references.
    
    Deserializing into a temporary is very common, however. See for example
    things like 's >> VARINT(n)'. The VARINT macro produces a temporary wrapper
    that holds a reference to n.
    
    Fix this by accepting non-const rvalue references instead of lvalue references.
    We don't propagate the rvalue-ness down, as there are no useful optimizations
    that only apply to temporaries.
    
    Then use this new functionality to get rid of many (but not all) uses of the
    'REF' macro (which casts away constness).
    172f5fa738
  4. fanquake added the label Refactoring on Mar 14, 2018
  5. sipa requested review from eklitzke on Mar 14, 2018
  6. sipa requested review from ryanofsky on Mar 14, 2018
  7. kallewoof commented at 4:29 am on March 14, 2018: member
    utACK 172f5fa738d419efda99542e2ad2a0f4db5be580
  8. eklitzke approved
  9. eklitzke commented at 8:09 am on March 14, 2018: contributor

    utACK 172f5fa738d419efda99542e2ad2a0f4db5be580

    I want to test this later (mostly for my own curiosity), but technically on x86 a variadic function call is not the same as std::forward. The max difference is a loss of one register (that the compiler can probably optimize away anyway).

  10. sipa commented at 5:51 pm on March 14, 2018: member

    technically on x86 a variadic function call is not the same as std::forward

    I have no idea what the context for this is or what you’re trying to say.

    This PRs removes some std::forwards because they’re not necessary (see commit message), and it simplifies the code not to distinguish. This PR is not intended as a performance improvement.

  11. ryanofsky commented at 5:09 pm on March 15, 2018: member
    utACK 172f5fa738d419efda99542e2ad2a0f4db5be580. I really like these nice, self-contained cleanups from #10785.
  12. sipa merged this on Mar 15, 2018
  13. sipa closed this on Mar 15, 2018

  14. sipa referenced this in commit 7be9a9a570 on Mar 15, 2018
  15. promag commented at 11:59 pm on March 15, 2018: member
    utACK 172f5fa.
  16. PastaPastaPasta referenced this in commit 9a6cf658f5 on Dec 16, 2020
  17. UdjinM6 referenced this in commit ec71097801 on Dec 17, 2020
  18. furszy referenced this in commit a87f8595fc on Apr 8, 2021
  19. MarcoFalke 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: 2024-12-18 18:12 UTC

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