bench: Construct CTxOut and COutPoint in a single expression - #36019
Open
alexanderwiederin wants to merge 1 commit into
Open
bench: Construct CTxOut and COutPoint in a single expression#36019alexanderwiederin wants to merge 1 commit into
alexanderwiederin wants to merge 1 commit into
Conversation
Contributor
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36019. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste |
maflcko
reviewed
Aug 19, 2026
Replace separate member assignments with brace initialization. The narrowing conversions from size_t are now explicit rather than implicit.
alexanderwiederin
force-pushed
the
bench-declarative
branch
from
August 19, 2026 09:00
361ee92 to
5d53932
Compare
josibake
approved these changes
Aug 19, 2026
| tx1.vout[i].scriptPubKey = CScript(); | ||
| // Each output progressively larger | ||
| tx1.vout[i].nValue = i * CENT; | ||
| tx1.vout[i] = CTxOut{static_cast<CAmount>(i) * CENT, CScript()}; |
Member
There was a problem hiding this comment.
I think slightly better is:
tx1.vout.reserve(number_outputs);
for (size_t i = 0; i < number_outputs; ++i) {
tx1.vout.push_back(
CTxOut{static_cast<CAmount>(i) * CENT, CScript{}}
);
}.. as I find it improves the readability and also keeps the type being constructed clearly visible. If performance were a concern you could do:
tx1.vout.reserve(number_outputs);
for (size_t i = 0; i < number_outputs; ++i) {
tx1.vout.emplace_back(
static_cast<CAmount>(i) * CENT,
CScript{}
);
}but considering this really hurts the readability I wouldn't suggest it here.
| for (size_t i = 0; i < tx2.vin.size(); i++) { | ||
| tx2.vin[i].prevout.hash = parent_txid; | ||
| tx2.vin[i].prevout.n = i; | ||
| tx2.vin[i].prevout = COutPoint{parent_txid, static_cast<uint32_t>(i)}; |
Member
There was a problem hiding this comment.
Same suggestion as above with:
tx2.reserve(tx1.vout.size());
for (size_t i = 0; i < tx2.vin.size(); i++) {
tx2.push_back(
COutPoint{parent_txid, static_cast<uint32_t>(i)}
);
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces field-by-field mutation of
CTxOutandCOutPointin two bench files with brace initialisation, which requires thesize_tconversions to be made explicit.Noticed while looking at #35994, where switching the proposed fix-it to
{}surfaces implicit narrowing conversions like these.The constructed values are unchanged.
Note: Only the sites where a conversion is involved are included in this PR; the remaining field-by-field construction in
bench/would be covered by #35994's follow-ups.