From bd08a008b42dac921bd9c031637e378899c1cd1d Mon Sep 17 00:00:00 2001 From: Martin Leitner-Ankerl Date: Wed, 2 Aug 2023 20:01:52 +0200 Subject: [PATCH] refactor: use fold expressions instead of recursive calls in SerializeMany() Instead of recursively calling `SerializeMany` and peeling off one argument at a time, use a fold expression. This simplifies the code, makes it most likely faster because it reduces the number of function calls, and compiles faster because there are fewer template instantiations. --- src/serialize.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/serialize.h b/src/serialize.h index 0cda0ac7d5e..a56df871e7d 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -1039,16 +1039,10 @@ public: int GetVersion() const { return nVersion; } }; -template -void SerializeMany(Stream& s) +template +void SerializeMany(Stream& s, const Args&... args) { -} - -template -void SerializeMany(Stream& s, const Arg& arg, const Args&... args) -{ - ::Serialize(s, arg); - ::SerializeMany(s, args...); + (::Serialize(s, args), ...); } template