mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 18:53:23 -03:00
script: actually trigger the optimization in BuildScript
The counter is an optimization over calling `ret.empty()`. It was suggested that the compiler would realize `cnt` is only `0` on the first iteration, and not actually emit the check and conditional. This optimization was actually not triggered at all, since we incremented `cnt` at the beginning of the first iteration. Fix it by incrementing at the end instead. This was reported by Github user "Janus".
This commit is contained in:
parent
31c1b14754
commit
00897d0677
1 changed files with 1 additions and 1 deletions
|
@ -588,7 +588,6 @@ CScript BuildScript(Ts&&... inputs)
|
|||
int cnt{0};
|
||||
|
||||
([&ret, &cnt] (Ts&& input) {
|
||||
cnt++;
|
||||
if constexpr (std::is_same_v<std::remove_cv_t<std::remove_reference_t<Ts>>, CScript>) {
|
||||
// If it is a CScript, extend ret with it. Move or copy the first element instead.
|
||||
if (cnt == 0) {
|
||||
|
@ -600,6 +599,7 @@ CScript BuildScript(Ts&&... inputs)
|
|||
// Otherwise invoke CScript::operator<<.
|
||||
ret << input;
|
||||
}
|
||||
cnt++;
|
||||
} (std::forward<Ts>(inputs)), ...);
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Add table
Reference in a new issue