Skip to content

Commit 098356b

Browse files
committed
Handle trivially serializable types (types like arithmetic and enum types which can be read and written as raw bytes)
1 parent f642e80 commit 098356b

File tree

4 files changed

+389
-70
lines changed

4 files changed

+389
-70
lines changed

src/sst/core/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ nobase_dist_sst_HEADERS = \
109109
serialization/impl/packer.h \
110110
serialization/impl/sizer.h \
111111
serialization/impl/serialize_string.h \
112+
serialization/impl/serialize_trivial.h \
112113
serialization/impl/unpacker.h \
113114
serialization/serializer.h \
114115
serialization/serializer_fwd.h \

src/sst/core/serialization/impl/serialize_array.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"The header file sst/core/serialization/impl/serialize_array.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serialize.h"
1818
#endif
1919

20+
#include "serialize_trivial.h"
2021
#include "sst/core/serialization/serializer.h"
2122

2223
#include <array>
@@ -68,12 +69,6 @@ serialize_array_map_element(serializer& ser, void* data, ser_opt_t opt, size_t i
6869
sst_ser_object(ser, static_cast<ELEM_T*>(data)[index], opt, name);
6970
}
7071

71-
// Whether the element type is copyable with memcpy()
72-
// TODO: Implement with std::is_trivially_copyable and std::is_aggregate, using reflection to check for troublesome
73-
// members like pointers
74-
template <typename T>
75-
constexpr bool is_trivial_element_v = std::is_arithmetic_v<T> || std::is_enum_v<T>;
76-
7772
// Serialize fixed arrays
7873
// ELEM_T: Array element type
7974
// SIZE: Fixed array size
@@ -99,7 +94,9 @@ struct serialize_impl_fixed_array
9994
[[fallthrough]];
10095

10196
default:
102-
if constexpr ( is_trivial_element_v<ELEM_T> )
97+
// TODO: How to handle array-of-array
98+
// is_trivially_serializable_excluded_v<ELEM_T> can be added to exclude arrays-of-arrays from the fast path
99+
if constexpr ( is_trivially_serializable_v<ELEM_T> )
103100
ser.raw(&(*aPtr)[0], sizeof(ELEM_T) * SIZE);
104101
else
105102
serialize_array(ser, &(*aPtr)[0], elem_opt, SIZE, serialize_array_element<ELEM_T>);
@@ -152,7 +149,9 @@ class serialize_impl<pvt::array_wrapper<ELEM_T, SIZE_T>>
152149
break;
153150

154151
default:
155-
if constexpr ( std::is_void_v<ELEM_T> || pvt::is_trivial_element_v<ELEM_T> )
152+
// TODO: How to handle array-of-array
153+
// is_trivially_serializable_excluded_v<ELEM_T> can be added to exclude arrays-of-arrays from the fast path
154+
if constexpr ( std::is_void_v<ELEM_T> || is_trivially_serializable_v<ELEM_T> )
156155
ser.binary(ary.ptr, ary.size);
157156
else {
158157
ser.primitive(ary.size);

0 commit comments

Comments
 (0)