Skip to content

Commit bd08a00

Browse files
committed
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.
1 parent 2fa60f0 commit bd08a00

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/serialize.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,16 +1039,10 @@ class CSizeComputer
10391039
int GetVersion() const { return nVersion; }
10401040
};
10411041

1042-
template<typename Stream>
1043-
void SerializeMany(Stream& s)
1044-
{
1045-
}
1046-
1047-
template<typename Stream, typename Arg, typename... Args>
1048-
void SerializeMany(Stream& s, const Arg& arg, const Args&... args)
1042+
template <typename Stream, typename... Args>
1043+
void SerializeMany(Stream& s, const Args&... args)
10491044
{
1050-
::Serialize(s, arg);
1051-
::SerializeMany(s, args...);
1045+
(::Serialize(s, args), ...);
10521046
}
10531047

10541048
template<typename Stream>

0 commit comments

Comments
 (0)