Skip to content

Commit 00897d0

Browse files
committed
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".
1 parent 31c1b14 commit 00897d0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/script/script.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,6 @@ CScript BuildScript(Ts&&... inputs)
588588
int cnt{0};
589589

590590
([&ret, &cnt] (Ts&& input) {
591-
cnt++;
592591
if constexpr (std::is_same_v<std::remove_cv_t<std::remove_reference_t<Ts>>, CScript>) {
593592
// If it is a CScript, extend ret with it. Move or copy the first element instead.
594593
if (cnt == 0) {
@@ -600,6 +599,7 @@ CScript BuildScript(Ts&&... inputs)
600599
// Otherwise invoke CScript::operator<<.
601600
ret << input;
602601
}
602+
cnt++;
603603
} (std::forward<Ts>(inputs)), ...);
604604

605605
return ret;

0 commit comments

Comments
 (0)