diff options
author | Antoine Poinsot <darosior@protonmail.com> | 2022-07-26 13:02:48 +0200 |
---|---|---|
committer | Antoine Poinsot <darosior@protonmail.com> | 2022-07-26 13:02:48 +0200 |
commit | 00897d0677c2cb6609b90d52b89907c8b50d6de0 (patch) | |
tree | f1213794c1c8402ae41f5b5d9b36f02ce2429c51 /src | |
parent | 31c1b14754574b0b0a54587e937fab66b3b85e39 (diff) |
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".
Diffstat (limited to 'src')
-rw-r--r-- | src/script/script.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/script/script.h b/src/script/script.h index 3b799ad637..1e5f694d52 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -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; |