@@ -710,14 +710,12 @@ template<typename Stream, typename C> void Unserialize(Stream& is, std::basic_st
710
710
711
711
/* *
712
712
* prevector
713
- * prevectors of unsigned char are a special case and are intended to be serialized as a single opaque blob.
714
713
*/
715
714
template <typename Stream, unsigned int N, typename T> inline void Serialize (Stream& os, const prevector<N, T>& v);
716
715
template <typename Stream, unsigned int N, typename T> inline void Unserialize (Stream& is, prevector<N, T>& v);
717
716
718
717
/* *
719
718
* vector
720
- * vectors of unsigned char are a special case and are intended to be serialized as a single opaque blob.
721
719
*/
722
720
template <typename Stream, typename T, typename A> inline void Serialize (Stream& os, const std::vector<T, A>& v);
723
721
template <typename Stream, typename T, typename A> inline void Unserialize (Stream& is, std::vector<T, A>& v);
@@ -820,10 +818,9 @@ void Unserialize(Stream& is, std::basic_string<C>& str)
820
818
template <typename Stream, unsigned int N, typename T>
821
819
void Serialize (Stream& os, const prevector<N, T>& v)
822
820
{
823
- if constexpr (std::is_same_v<T, unsigned char >) {
821
+ if constexpr (BasicByte<T >) { // Use optimized version for unformatted basic bytes
824
822
WriteCompactSize (os, v.size ());
825
- if (!v.empty ())
826
- os.write (MakeByteSpan (v));
823
+ if (!v.empty ()) os.write (MakeByteSpan (v));
827
824
} else {
828
825
Serialize (os, Using<VectorFormatter<DefaultFormatter>>(v));
829
826
}
@@ -833,7 +830,7 @@ void Serialize(Stream& os, const prevector<N, T>& v)
833
830
template <typename Stream, unsigned int N, typename T>
834
831
void Unserialize (Stream& is, prevector<N, T>& v)
835
832
{
836
- if constexpr (std::is_same_v<T, unsigned char >) {
833
+ if constexpr (BasicByte<T >) { // Use optimized version for unformatted basic bytes
837
834
// Limit size per read so bogus size value won't cause out of memory
838
835
v.clear ();
839
836
unsigned int nSize = ReadCompactSize (is);
@@ -856,10 +853,9 @@ void Unserialize(Stream& is, prevector<N, T>& v)
856
853
template <typename Stream, typename T, typename A>
857
854
void Serialize (Stream& os, const std::vector<T, A>& v)
858
855
{
859
- if constexpr (std::is_same_v<T, unsigned char >) {
856
+ if constexpr (BasicByte<T >) { // Use optimized version for unformatted basic bytes
860
857
WriteCompactSize (os, v.size ());
861
- if (!v.empty ())
862
- os.write (MakeByteSpan (v));
858
+ if (!v.empty ()) os.write (MakeByteSpan (v));
863
859
} else if constexpr (std::is_same_v<T, bool >) {
864
860
// A special case for std::vector<bool>, as dereferencing
865
861
// std::vector<bool>::const_iterator does not result in a const bool&
@@ -877,7 +873,7 @@ void Serialize(Stream& os, const std::vector<T, A>& v)
877
873
template <typename Stream, typename T, typename A>
878
874
void Unserialize (Stream& is, std::vector<T, A>& v)
879
875
{
880
- if constexpr (std::is_same_v<T, unsigned char >) {
876
+ if constexpr (BasicByte<T >) { // Use optimized version for unformatted basic bytes
881
877
// Limit size per read so bogus size value won't cause out of memory
882
878
v.clear ();
883
879
unsigned int nSize = ReadCompactSize (is);
0 commit comments