constexpr: Increase constexpr usage in strencodings #15576

pull ldm5180 wants to merge 1 commits into bitcoin:master from ldm5180:constexpr-strencodings changing 2 files +10 −8
  1. ldm5180 commented at 1:03 AM on March 11, 2019: contributor

    Problem:

    • Several items in strencodings.h/cpp are known at compile-time, but are being computed at run-time due to not being labelled as constexpr.
    • Several items in strencodings.h/cpp are marked static when they are meant to be locally scoped variables.

    Solution:

    • Mark items constexpr when they can be.
    • Remove static qualifier when possible so that variables which are meant to only be used locally are not bloating the final binary by residing in the data segment.
  2. constexpr: Increase constexpr usage in strencodings
    Problem:
    - Several items in strencodings.h/cpp are known at compile-time, but are being computed at run-time due to not being labelled as `constexpr`.
    - Several items in strencodings.h/cpp are marked `static` when they are meant to be locally scoped variables.
    
    Solution:
    - Mark items `constexpr` when they can be.
    - Remove `static` qualifier when possible so that variables which are
      meant to only be used locally are not bloating the final binary by
      residing in the `data` segment.
    d41522b9f3
  3. fanquake added the label Refactoring on Mar 11, 2019
  4. DrahtBot commented at 1:46 AM on March 11, 2019: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #15573 (dead code: Remove dead option in HexStr conversion by ldm5180)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  5. MarcoFalke commented at 3:44 AM on March 11, 2019: member

    static const vs constexpr vs static constexpr for POD is a stylistic difference without any effect on the compiled binary.

    Stylistic changes without rationale are generally not accepted.

  6. in src/util/strencodings.cpp:147 in d41522b9f3
     143 | @@ -143,7 +144,7 @@ std::string EncodeBase64(const std::string& str)
     144 |  
     145 |  std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)
     146 |  {
     147 | -    static const int decode64_table[256] =
     148 | +    constexpr std::array<int,256> decode64_table =
    


    promag commented at 2:37 PM on March 11, 2019:

    IMO there is no gain using std::array in these cases.


    practicalswift commented at 4:30 PM on March 11, 2019:

    FWIW, this is what the C++ Core Guidelines say about the gains of using std::array:s instead of C arrays in the general case:

    Adding as a friendly general reference - not as a comment on the merits of these specific changes :-)

  7. DrahtBot added the label Needs rebase on Mar 12, 2019
  8. DrahtBot commented at 12:18 PM on March 12, 2019: member

    <!--cf906140f33d8803c4a75a2196329ecb-->Needs rebase

  9. MarcoFalke commented at 5:21 PM on April 19, 2019: member

    No activity for more than a month. Closing for now. Let me know if you want me to reopen this

  10. MarcoFalke closed this on Apr 19, 2019

  11. laanwj removed the label Needs rebase on Oct 24, 2019
  12. DrahtBot locked this on Dec 16, 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-22 06:15 UTC

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