From 49b8ccea28682a4412b2533a1b29f27eb145c93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 8 Feb 2023 23:02:05 +0100 Subject: [PATCH] Fix magic_enum compilation times (#4113) --- nano/lib/CMakeLists.txt | 1 + nano/lib/magic_enum.hpp | 3 --- nano/lib/stats_enums.cpp | 21 +++++++++++++++++++++ nano/lib/stats_enums.hpp | 23 +++++------------------ nano/test_common/rate_observer.cpp | 4 +--- 5 files changed, 28 insertions(+), 24 deletions(-) delete mode 100644 nano/lib/magic_enum.hpp create mode 100644 nano/lib/stats_enums.cpp diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index 5d003f591..51d9cd020 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -69,6 +69,7 @@ add_library( stats.hpp stats.cpp stats_enums.hpp + stats_enums.cpp stream.hpp threading.hpp threading.cpp diff --git a/nano/lib/magic_enum.hpp b/nano/lib/magic_enum.hpp deleted file mode 100644 index 3d82e22f3..000000000 --- a/nano/lib/magic_enum.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#define MAGIC_ENUM_RANGE_MIN 0 -#define MAGIC_ENUM_RANGE_MAX 256 -#include \ No newline at end of file diff --git a/nano/lib/stats_enums.cpp b/nano/lib/stats_enums.cpp new file mode 100644 index 000000000..0e77882d6 --- /dev/null +++ b/nano/lib/stats_enums.cpp @@ -0,0 +1,21 @@ +#include + +#define MAGIC_ENUM_RANGE_MIN 0 +#define MAGIC_ENUM_RANGE_MAX 256 + +#include + +std::string_view nano::to_string (nano::stat::type type) +{ + return magic_enum::enum_name (type); +} + +std::string_view nano::to_string (nano::stat::detail detail) +{ + return magic_enum::enum_name (detail); +} + +std::string_view nano::to_string (nano::stat::dir dir) +{ + return magic_enum::enum_name (dir); +} \ No newline at end of file diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index 7db0a30f3..0220834a2 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -1,6 +1,7 @@ #pragma once -#include +#include +#include namespace nano::stat { @@ -277,21 +278,7 @@ enum class dir : uint8_t namespace nano { -/** Returns string representation of type */ -inline std::string_view to_string (stat::type type) -{ - return magic_enum::enum_name (type); -} - -/** Returns string representation of detail */ -inline std::string_view to_string (stat::detail detail) -{ - return magic_enum::enum_name (detail); -} - -/** Returns string representation of dir */ -inline std::string_view to_string (stat::dir dir) -{ - return magic_enum::enum_name (dir); -} +std::string_view to_string (stat::type type); +std::string_view to_string (stat::detail detail); +std::string_view to_string (stat::dir dir); } \ No newline at end of file diff --git a/nano/test_common/rate_observer.cpp b/nano/test_common/rate_observer.cpp index 4abf42b72..b2fb89174 100644 --- a/nano/test_common/rate_observer.cpp +++ b/nano/test_common/rate_observer.cpp @@ -4,8 +4,6 @@ #include -using namespace magic_enum::ostream_operators; - /* * rate_observer::counter */ @@ -49,7 +47,7 @@ uint64_t nano::test::rate_observer::stat_counter::count () std::string nano::test::rate_observer::stat_counter::name () { std::stringstream ss; - ss << type << "::" << detail << "::" << dir; + ss << nano::to_string (type) << "::" << nano::to_string (detail) << "::" << nano::to_string (dir); return ss.str (); }