From 54db7941d088d1043cf2eb4a7e85ec1e9c0c9895 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Sat, 26 Jun 2021 12:14:17 +0200 Subject: [PATCH] tuning mesh(un)pickling --- libsrc/core/archive.hpp | 4 +++- libsrc/meshing/meshtype.hpp | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/libsrc/core/archive.hpp b/libsrc/core/archive.hpp index 7c7db7d5..fc318e55 100644 --- a/libsrc/core/archive.hpp +++ b/libsrc/core/archive.hpp @@ -207,7 +207,7 @@ namespace ngcore Do(&v[0], size); return (*this); } - + // archive implementation for enums template auto operator & (T& val) -> std::enable_if_t::value, Archive&> @@ -809,6 +809,8 @@ namespace ngcore return *this; } + Archive & Do (std::byte * d, size_t n) override + { stream->read(reinterpret_cast(d), n*sizeof(std::byte)); return *this; } // NOLINT Archive & Do (double * d, size_t n) override { stream->read(reinterpret_cast(d), n*sizeof(double)); return *this; } // NOLINT Archive & Do (int * i, size_t n) override diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 978e7b29..42448af1 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -840,6 +840,7 @@ namespace netgen void DoArchive (Archive & ar) { + /* short _np, _typ; bool _curved; if (ar.Output()) @@ -847,10 +848,24 @@ namespace netgen ar & _np & _typ & index & _curved; if (ar.Input()) { np = _np; typ = ELEMENT_TYPE(_typ); is_curved = _curved; } - /* - for (size_t i = 0; i < np; i++) - ar & pnum[i]; */ + + if (ar.Output()) + { + short _np, _typ; + bool _curved; + _np = np; _typ = typ; _curved = is_curved; + ar & _np & _typ & index & _curved; + } + else + { + alignas (4) std::byte tmp[9]; + ar.Do (&tmp[0], 9); + np = *(short*)(void*)&tmp[0]; + typ = ELEMENT_TYPE(*(short*)(void*)&tmp[2]); + index = *(int*)(void*)&tmp[4]; + is_curved = *(bool*)(void*)&tmp[8]; + } static_assert(sizeof(int) == sizeof (PointIndex)); ar.Do( (int*)&pnum[0], np); }