@@ -643,8 +643,6 @@ template<typename Stream, typename C> void Unserialize(Stream& is, std::basic_st
643
643
* prevectors of unsigned char are a special case and are intended to be serialized as a single opaque blob.
644
644
*/
645
645
template <typename Stream, unsigned int N, typename T> inline void Serialize (Stream& os, const prevector<N, T>& v);
646
- template <typename Stream, unsigned int N, typename T> void Unserialize_impl (Stream& is, prevector<N, T>& v, const unsigned char &);
647
- template <typename Stream, unsigned int N, typename T, typename V> void Unserialize_impl (Stream& is, prevector<N, T>& v, const V&);
648
646
template <typename Stream, unsigned int N, typename T> inline void Unserialize (Stream& is, prevector<N, T>& v);
649
647
650
648
/* *
@@ -762,35 +760,25 @@ void Serialize(Stream& os, const prevector<N, T>& v)
762
760
}
763
761
764
762
765
- template <typename Stream, unsigned int N, typename T>
766
- void Unserialize_impl (Stream& is, prevector<N, T>& v, const unsigned char & )
763
+ template <typename Stream, unsigned int N, typename T>
764
+ void Unserialize (Stream& is, prevector<N, T>& v)
767
765
{
768
- // Limit size per read so bogus size value won't cause out of memory
769
- v.clear ();
770
- unsigned int nSize = ReadCompactSize (is);
771
- unsigned int i = 0 ;
772
- while (i < nSize)
773
- {
774
- unsigned int blk = std::min (nSize - i, (unsigned int )(1 + 4999999 / sizeof (T)));
775
- v.resize_uninitialized (i + blk);
776
- is.read (AsWritableBytes (Span{&v[i], blk}));
777
- i += blk;
766
+ if constexpr (std::is_same_v<T, unsigned char >) {
767
+ // Limit size per read so bogus size value won't cause out of memory
768
+ v.clear ();
769
+ unsigned int nSize = ReadCompactSize (is);
770
+ unsigned int i = 0 ;
771
+ while (i < nSize) {
772
+ unsigned int blk = std::min (nSize - i, (unsigned int )(1 + 4999999 / sizeof (T)));
773
+ v.resize_uninitialized (i + blk);
774
+ is.read (AsWritableBytes (Span{&v[i], blk}));
775
+ i += blk;
776
+ }
777
+ } else {
778
+ Unserialize (is, Using<VectorFormatter<DefaultFormatter>>(v));
778
779
}
779
780
}
780
781
781
- template <typename Stream, unsigned int N, typename T, typename V>
782
- void Unserialize_impl (Stream& is, prevector<N, T>& v, const V&)
783
- {
784
- Unserialize (is, Using<VectorFormatter<DefaultFormatter>>(v));
785
- }
786
-
787
- template <typename Stream, unsigned int N, typename T>
788
- inline void Unserialize (Stream& is, prevector<N, T>& v)
789
- {
790
- Unserialize_impl (is, v, T ());
791
- }
792
-
793
-
794
782
795
783
/* *
796
784
* vector
0 commit comments