From f15570200846b9bfe529137b83a451bd6800a91c Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 20 Apr 2014 23:40:32 +0400 Subject: [PATCH] Data type registrator went the same way - using plain statics instead of in-place allocation at first call. For code size critical applications, GCC flag -fno-threadsafe-statics should be used --- .../uavcan/node/global_data_type_registry.hpp | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/libuavcan/include/uavcan/node/global_data_type_registry.hpp b/libuavcan/include/uavcan/node/global_data_type_registry.hpp index e3402fe0e1..5fed147554 100644 --- a/libuavcan/include/uavcan/node/global_data_type_registry.hpp +++ b/libuavcan/include/uavcan/node/global_data_type_registry.hpp @@ -139,39 +139,23 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::regist(DataTypeID i { return RegistResultFrozen; } - - static union + static Entry entry; { - uint8_t buffer[sizeof(Entry)]; - long long _aligner_1; - long double _aligner_2; - } storage; - static bool constructed = false; - if (!constructed) - { - new (storage.buffer) Entry(); - constructed = true; - } - - Entry* const entry = reinterpret_cast(storage.buffer); - - { - const RegistResult remove_res = remove(entry); + const RegistResult remove_res = remove(&entry); if (remove_res != RegistResultOk) { return remove_res; } } - new (storage.buffer) Entry(DataTypeKind(Type::DataTypeKind), id, Type::getDataTypeSignature(), - Type::getDataTypeFullName()); + entry = Entry(DataTypeKind(Type::DataTypeKind), id, Type::getDataTypeSignature(), Type::getDataTypeFullName()); { - const RegistResult remove_res = remove(entry); + const RegistResult remove_res = remove(&entry); if (remove_res != RegistResultOk) { return remove_res; } } - return registImpl(entry); + return registImpl(&entry); } }