From 0207ee85b756730a880b7aa1b0fe33c9d4221fbb Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Fri, 27 Jun 2025 22:29:24 +0800 Subject: [PATCH] [Optimize] (MG_Util/Debug): avoid runtime cost of unneeded log function (forced at compile time) --- MG/MG_UTIL/Debug/Debug.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/MG/MG_UTIL/Debug/Debug.cpp b/MG/MG_UTIL/Debug/Debug.cpp index f04a0e47..7c79b411 100644 --- a/MG/MG_UTIL/Debug/Debug.cpp +++ b/MG/MG_UTIL/Debug/Debug.cpp @@ -92,14 +92,16 @@ namespace MG_Util::Debug { #define DECLARE_LOG_FUNCTION(name, level) \ void Log##name(const char* format, ...) { \ - va_list args; \ - va_start(args, format); \ - LogImpl(MG_Constants::Common::LOG_LEVEL_##level, \ - #level, \ - format, \ - ANDROID_LOG_##level, \ - args); \ - va_end(args); \ + if constexpr (MG_Global::Common::LogLevel <= MG_Constants::Common::LOG_LEVEL_##level) { \ + va_list args; \ + va_start(args, format); \ + LogImpl(MG_Constants::Common::LOG_LEVEL_##level, \ + #level, \ + format, \ + ANDROID_LOG_##level, \ + args); \ + va_end(args); \ + } \ } DECLARE_LOG_FUNCTION(D, DEBUG)