diff --git a/src/serialize.h b/src/serialize.h index 72672b459e4..39f2c0f3ae7 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -650,8 +650,6 @@ template inline void Unserialize(St * vectors of unsigned char are a special case and are intended to be serialized as a single opaque blob. */ template inline void Serialize(Stream& os, const std::vector& v); -template void Unserialize_impl(Stream& is, std::vector& v, const unsigned char&); -template void Unserialize_impl(Stream& is, std::vector& v, const V&); template inline void Unserialize(Stream& is, std::vector& v); /** @@ -801,35 +799,25 @@ void Serialize(Stream& os, const std::vector& v) } -template -void Unserialize_impl(Stream& is, std::vector& v, const unsigned char&) +template +void Unserialize(Stream& is, std::vector& v) { - // Limit size per read so bogus size value won't cause out of memory - v.clear(); - unsigned int nSize = ReadCompactSize(is); - unsigned int i = 0; - while (i < nSize) - { - unsigned int blk = std::min(nSize - i, (unsigned int)(1 + 4999999 / sizeof(T))); - v.resize(i + blk); - is.read(AsWritableBytes(Span{&v[i], blk})); - i += blk; + if constexpr (std::is_same_v) { + // Limit size per read so bogus size value won't cause out of memory + v.clear(); + unsigned int nSize = ReadCompactSize(is); + unsigned int i = 0; + while (i < nSize) { + unsigned int blk = std::min(nSize - i, (unsigned int)(1 + 4999999 / sizeof(T))); + v.resize(i + blk); + is.read(AsWritableBytes(Span{&v[i], blk})); + i += blk; + } + } else { + Unserialize(is, Using>(v)); } } -template -void Unserialize_impl(Stream& is, std::vector& v, const V&) -{ - Unserialize(is, Using>(v)); -} - -template -inline void Unserialize(Stream& is, std::vector& v) -{ - Unserialize_impl(is, v, T()); -} - - /** * pair