aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMacroFake <falke.marco@gmail.com>2022-07-30 17:48:31 +0200
committerMacroFake <falke.marco@gmail.com>2022-07-30 17:49:02 +0200
commit5215c80edcd031acf3911e8d824a843f817c6900 (patch)
tree800de7259b62e74f9c8fbd0c11b61c5c7507ce92 /src
parent8e37afcb132599f59c887162279b4e76003c66d8 (diff)
parent00897d0677c2cb6609b90d52b89907c8b50d6de0 (diff)
downloadbitcoin-5215c80edcd031acf3911e8d824a843f817c6900.tar.xz
Merge bitcoin/bitcoin#25709: script: actually trigger the optimization in BuildScript
00897d0677c2cb6609b90d52b89907c8b50d6de0 script: actually trigger the optimization in BuildScript (Antoine Poinsot) Pull request description: 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". Fixes #25682. Note this does *not* change semantics. It only allows the optimization of moving instead of copying on first `CScript` element to actually be reachable. ACKs for top commit: sipa: utACK 00897d0677c2cb6609b90d52b89907c8b50d6de0 MarcoFalke: review ACK 00897d0677c2cb6609b90d52b89907c8b50d6de0 Tree-SHA512: b575bd444b0cd2fe754ec5f3e2f3f53d2696d5dcebedcace1e38be372c82365e75938dfe185429ed5a83efe1a395e204bfb33efe56c10defc5811eaee50580e3
Diffstat (limited to 'src')
-rw-r--r--src/script/script.h2
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;