From 1403d181c106bc271ad2522adebde07c7850069b Mon Sep 17 00:00:00 2001 From: Martin Leitner-Ankerl Date: Wed, 2 Aug 2023 20:03:24 +0200 Subject: [PATCH] refactor: use fold expressions instead of recursive calls in UnserializeMany() Instead of recursively calling `UnserializeMany` 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 a56df871e7..aa9f834654 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -1045,16 +1045,10 @@ void SerializeMany(Stream& s, const Args&... args) (::Serialize(s, args), ...); } -template -inline void UnserializeMany(Stream& s) +template +inline void UnserializeMany(Stream& s, Args&&... args) { -} - -template -inline void UnserializeMany(Stream& s, Arg&& arg, Args&&... args) -{ - ::Unserialize(s, arg); - ::UnserializeMany(s, args...); + (::Unserialize(s, args), ...); } template