Both are fine and this refactor doesn't change any behavior.
However, inline constexpr from C++17 will ensure each symbol has a single address
across all TU, making the release binary minimally smaller. (For me it is smaller by about 1kB)
Both are fine and this refactor doesn't change any behavior.
However, inline constexpr from C++17 will ensure each symbol has a single address
across all TU, making the release binary minimally smaller. (For me it is smaller by about 1kB)
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35852.
<!--021abf342d371248e50ceaed478a90ca-->
See the guideline and AI policy for information on the review process.
| Type | Reviewers |
|---|---|
| ACK | fanquake |
If your review is incorrectly listed, please copy-paste <code><!--meta-tag:bot-skip--></code> into the comment that the bot should ignore.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
dbcache setter and clarify defaults by l0rinc)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.
<!--5faf32d7da4f0f540f40219e4f7537a3-->
Concept ACK - Could change static const here too? Not sure it's worth adding to the dev notes that inline constexpr is generally preferred (over static constexpr, static const etc)?
22 | @@ -23,7 +23,7 @@ 23 | namespace util { 24 | namespace detail { 25 | template <unsigned num_params> 26 | -constexpr static void CheckNumFormatSpecifiers(const char* str)
fac31e6 refactor: Manually use inline constexpr over constexpr static:
This is already implicitly inline, if we're changing it in a separate commit, we might as well remove the modifier, preferably as a first commit, which would allow us to fix the other case here in the scripted diff.
And maybe cover https://github.com/bitcoin/bitcoin/blob/fa5f29774872d18febc0df38831a6e45f3de69cc/src/net_permissions.h#L49 as well, similarly removing both qualifiers.
Sure, done both.
17 | /* A delay between shutdown pollings */ 18 | -static constexpr auto SHUTDOWN_POLLING_DELAY{200ms}; 19 | +inline constexpr auto SHUTDOWN_POLLING_DELAY{200ms}; 20 | 21 | /* AskPassphraseDialog -- Maximum passphrase length */ 22 | static const int MAX_PASSPHRASE_SIZE = 1024;
fac31e6 refactor: Manually use inline constexpr over constexpr static:
Maybe we could extend the PR to cover these as well (edit: #35852 (comment))
Sure, seems few enough to just include here as well.
24 | @@ -25,7 +25,7 @@ typedef struct secp256k1_context_struct secp256k1_context; 25 | typedef std::vector<unsigned char, secure_allocator<unsigned char> > CPrivKey; 26 | 27 | /** Size of ECDH shared secrets. */ 28 | -constexpr static size_t ECDH_SECRET_SIZE = CSHA256::OUTPUT_SIZE; 29 | +inline constexpr size_t ECDH_SECRET_SIZE{CSHA256::OUTPUT_SIZE};
fac31e6 refactor: Manually use inline constexpr over constexpr static:
Could we rather extend the scripted diff to cover this?
<details><summary>extended scripted diff</summary>
sed -E -i 's/^(static constexpr|constexpr static)\>/inline constexpr/g' $( \
git grep -El '^(static constexpr|constexpr static)' -- \
'*.h' \
':(exclude)src/crc32c' \
':(exclude)src/ipc/libmultiprocess' \
':(exclude)src/minisketch' \
)
</details>
thx, done
Those functions have no need to be static in every TU. Also, static
somewhat contradicts and overwrites the inline keyword.
So remove the static, and just keep constexpr (which implies inline).
Both are fine and this refactor shouldn't change any behavior.
However, inline constexpr will ensure each symbol has a single address
across all TU, making the release binary smaller.
Review note: In theory the script may also cover functions, but they
were handled in the prior commit, to remove the redundant inline for
them.
-BEGIN VERIFY SCRIPT-
sed --regexp-extended -i 's/^(static constexpr|constexpr static)\>/inline constexpr/g' $( \
git grep --extended-regexp -l '^(static constexpr|constexpr static)' -- \
'*.h' \
':(exclude)src/crc32c' \
':(exclude)src/ipc/libmultiprocess' \
':(exclude)src/minisketch' \
)
-END VERIFY SCRIPT-
This is required for the next commit.
Both are fine and this refactor shouldn't change any behavior.
However, inline constexpr will ensure each symbol has a single address
across all TU, making the release binary smaller.
Note, a follow-up commit will deal with string literals (const char*)
and other static const, which can not be constexpr (e.g. std::vector).
-BEGIN VERIFY SCRIPT-
type='bool|CAmount|size_t|((signed|unsigned) )?int|u?int[0-9]+_t|std::array|DatabaseFormat|CFeeRate'
sed -i --regexp-extended "s/^static const (${type})\>/inline constexpr \1/" $( \
git grep -l "^static const " -- \
'*.h' \
':(exclude)src/leveldb' \
':(exclude)src/secp256k1' \
)
-END VERIFY SCRIPT-
This is needed for the next scripted-diff commit, which would otherwise
turn the const from `static const char*` into `inline const char*`.
Both are fine and this refactor shouldn't change any behavior.
However, inline const will ensure each symbol has a single address
across all TU, making the release binary smaller.
-BEGIN VERIFY SCRIPT-
sed -i "s/^static const /inline const /" $( \
git grep -l "^static const " -- \
'*.h' \
':(exclude)src/leveldb' \
':(exclude)src/secp256k1' \
)
-END VERIFY SCRIPT-ACK fac8a3a4a68bc7edabaaab6bfb113199792babb4