Skip to content
Snippets Groups Projects
Commit 3626bdf4 authored by Florian Fischer's avatar Florian Fischer
Browse files

[Debug.hpp] wrap actual logging in log-level constexpr

According to godbolt.org

do { if constexpr(false) { break; } int foo = 42; foo++; } while(false);

does result in code generation for gcc 10.2 and clang 11.0.1 as opposed to

do { if constexpr(false) { int foo = 42; foo++; }} while(false);

which does not result in code generation for both gcc and clang.

And this simple change did indeed significantly increases our echo
benchmark performance. We were probably creating a lot of std::stringstream
objects without ever using them.
parent 20f971e4
No related branches found
No related tags found
1 merge request!150[Debug.hpp] wrap actual logging in log-level constexpr
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#define EMPER_BUILD_STR(x) [&]() -> std::string {std::stringstream sst; sst << x; return sst.str(); } #define EMPER_BUILD_STR(x) [&]() -> std::string {std::stringstream sst; sst << x; return sst.str(); }
// NOLINTNEXTLINE(bugprone-macro-parentheses) // NOLINTNEXTLINE(bugprone-macro-parentheses)
#define LOG(level, x, log_func) do {if constexpr (level > EMPER_LOG_LEVEL) { break; } log_func(EMPER_BUILD_STR(x)()); } while (false) #define LOG(level, x, log_func) do { if constexpr (level <= EMPER_LOG_LEVEL) { log_func(EMPER_BUILD_STR(x)()); } } while (false)
// NOLINTNEXTLINE(bugprone-macro-parentheses) // NOLINTNEXTLINE(bugprone-macro-parentheses)
#define DBG(x) LOG(Debug, x, emper_log_no_prefix); #define DBG(x) LOG(Debug, x, emper_log_no_prefix);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment