diff options
author | Martin Leitner-Ankerl <martin.ankerl@gmail.com> | 2023-08-02 20:01:52 +0200 |
---|---|---|
committer | Martin Leitner-Ankerl <martin.ankerl@gmail.com> | 2023-08-03 10:30:02 +0200 |
commit | bd08a008b42dac921bd9c031637e378899c1cd1d (patch) | |
tree | 3ae66625cad26c294fbcc02616c035ca503c68ac | |
parent | 2fa60f0b683cefd7956273986dafe3bde00c98fd (diff) |
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.
-rw-r--r-- | src/serialize.h | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/src/serialize.h b/src/serialize.h index 0cda0ac7d5..a56df871e7 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -1039,16 +1039,10 @@ public: int GetVersion() const { return nVersion; } }; -template<typename Stream> -void SerializeMany(Stream& s) -{ -} - -template<typename Stream, typename Arg, typename... Args> -void SerializeMany(Stream& s, const Arg& arg, const Args&... args) +template <typename Stream, typename... Args> +void SerializeMany(Stream& s, const Args&... args) { - ::Serialize(s, arg); - ::SerializeMany(s, args...); + (::Serialize(s, args), ...); } template<typename Stream> |