refactor: performance-for-range-copy in psbt.h #30253

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2406-performance-for-range-copy changing 1 files +1 −1
  1. maflcko commented at 11:12 am on June 9, 2024: member

    A copy of the partial signatures is not required before serializing them.

    For reference, this was found by switching the codebase to std::span (not sure why it wasn’t found with Span though):

    0./psbt.h:240:23: error: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy,-warnings-as-errors]
    1  240 |             for (auto sig_pair : partial_sigs) {
    2      |                       ^
    3      |                  const  &
    
  2. refactor: performance-for-range-copy in psbt.h fab01b5220
  3. DrahtBot commented at 11:12 am on June 9, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK theStack, tdb3

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  4. DrahtBot added the label Refactoring on Jun 9, 2024
  5. maflcko commented at 11:13 am on June 9, 2024: member
  6. tdb3 commented at 3:15 pm on June 9, 2024: contributor

    Approach ACK. Less copying makes sense. Briefly searched for other instances in psbt.h where potentially unnecessary copying is done.

    Would it also make sense to adjust these references to const (or is there a specific reason why const should not be used here)? Adjusted to const auto& entry and ran unit and functional tests (no issues observed).

    https://github.com/bitcoin/bitcoin/blob/fab01b5220c28a334b451ed9625bd3914c48e6af/src/psbt.h#L355-L359

    https://github.com/bitcoin/bitcoin/blob/fab01b5220c28a334b451ed9625bd3914c48e6af/src/psbt.h#L780-L784

    https://github.com/bitcoin/bitcoin/blob/fab01b5220c28a334b451ed9625bd3914c48e6af/src/psbt.h#L1013-L1017

  7. maflcko commented at 3:25 pm on June 9, 2024: member

    Less copying makes sense. Briefly searched for other instances in psbt.h where potentially unnecessary copying is done.

    The examples you provided are already const references. In C++, when calling a member method that is marked const, member access will be const. Moreover, auto& is a reference that hides the type, including the const-ness, so const auto& and auto& should be identical in this context (const references that do not copy), and no further change should be needed.

  8. theStack approved
  9. theStack commented at 5:51 pm on June 9, 2024: contributor
    utACK fab01b5220c28a334b451ed9625bd3914c48e6af
  10. DrahtBot requested review from tdb3 on Jun 9, 2024
  11. tdb3 commented at 5:54 pm on June 9, 2024: contributor

    no further change should be needed.

    Thanks. ACK fab01b5220c28a334b451ed9625bd3914c48e6af

  12. fanquake merged this on Jun 10, 2024
  13. fanquake closed this on Jun 10, 2024

  14. maflcko deleted the branch on Jun 10, 2024
  15. luke-jr referenced this in commit 9691293934 on Jun 13, 2024
  16. PastaPastaPasta referenced this in commit 90d7cef8e1 on Feb 17, 2025
  17. PastaPastaPasta referenced this in commit 2b6290d0dc on Feb 19, 2025
  18. PastaPastaPasta referenced this in commit 7b8a2e040e on Feb 20, 2025
  19. PastaPastaPasta referenced this in commit a74b1e22f6 on Feb 20, 2025
  20. PastaPastaPasta referenced this in commit 456add22c3 on Feb 21, 2025
  21. bitcoin locked this on Jun 10, 2025

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: 2025-07-02 00:13 UTC

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