From fda7cfa2bc0dd2423fc2beae20b7458edaa64449 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Tue, 9 Jan 2024 10:01:11 +0100 Subject: [PATCH 1/2] function-pointer instead of std::function, no unique-ptr around type_register --- libsrc/core/archive.cpp | 20 ++++++++++---------- libsrc/core/archive.hpp | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/libsrc/core/archive.cpp b/libsrc/core/archive.cpp index 5454b929..d394c49c 100644 --- a/libsrc/core/archive.cpp +++ b/libsrc/core/archive.cpp @@ -10,24 +10,24 @@ namespace ngcore { // clang-tidy should ignore this static object - static std::unique_ptr> type_register; // NOLINT + static std::map type_register; // NOLINT const detail::ClassArchiveInfo& Archive :: GetArchiveRegister(const std::string& classname) { - if(type_register == nullptr) type_register = - std::make_unique>(); - return (*type_register)[classname]; + // if(type_register == nullptr) type_register = + // std::make_unique>(); + return (type_register)[classname]; } void Archive :: SetArchiveRegister(const std::string& classname, const detail::ClassArchiveInfo& info) { - if(type_register == nullptr) type_register = - std::make_unique>(); - (*type_register)[classname] = info; + // if(type_register == nullptr) type_register = + // std::make_unique>(); + (type_register)[classname] = info; } bool Archive :: IsRegistered(const std::string& classname) { - if(type_register == nullptr) type_register = - std::make_unique>(); - return type_register->count(classname) != 0; + // if(type_register == nullptr) type_register = + // std::make_unique>(); + return type_register.count(classname) != 0; } #ifdef NETGEN_PYTHON diff --git a/libsrc/core/archive.hpp b/libsrc/core/archive.hpp index 604a3f26..e9f28ef9 100644 --- a/libsrc/core/archive.hpp +++ b/libsrc/core/archive.hpp @@ -150,7 +150,8 @@ namespace ngcore void* (*downcaster)(const std::type_info&, void*); // Archive constructor arguments - std::function cargs_archiver; + // std::function cargs_archiver; + void (*cargs_archiver)(Archive&, void*); #ifdef NETGEN_PYTHON // std::function anyToPyCaster; From 54287bbfbb7c09627202f24a2958882ffb068ed7 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Tue, 9 Jan 2024 10:21:06 +0100 Subject: [PATCH 2/2] wrap static variable into function --- libsrc/core/archive.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libsrc/core/archive.cpp b/libsrc/core/archive.cpp index d394c49c..c4731562 100644 --- a/libsrc/core/archive.cpp +++ b/libsrc/core/archive.cpp @@ -10,24 +10,31 @@ namespace ngcore { // clang-tidy should ignore this static object - static std::map type_register; // NOLINT + // static std::map type_register; // NOLINT + + auto& GetTypeRegister() + { + static std::map type_register; + return type_register; + } + const detail::ClassArchiveInfo& Archive :: GetArchiveRegister(const std::string& classname) { // if(type_register == nullptr) type_register = // std::make_unique>(); - return (type_register)[classname]; + return GetTypeRegister()[classname]; } void Archive :: SetArchiveRegister(const std::string& classname, const detail::ClassArchiveInfo& info) { // if(type_register == nullptr) type_register = // std::make_unique>(); - (type_register)[classname] = info; + GetTypeRegister()[classname] = info; } bool Archive :: IsRegistered(const std::string& classname) { // if(type_register == nullptr) type_register = // std::make_unique>(); - return type_register.count(classname) != 0; + return GetTypeRegister().count(classname) != 0; } #ifdef NETGEN_PYTHON