From: terencehill Date: Thu, 21 Sep 2023 17:46:34 +0000 (+0200) Subject: Optimize _LOG_HEADER to avoid bloating compilation output files and reduce program... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=24dbe2f9d4a088443ab05844e2f4c0fa8e7fda37;p=xonotic%2Fxonotic-data.pk3dir.git Optimize _LOG_HEADER to avoid bloating compilation output files and reduce program size --- diff --git a/qcsrc/lib/log.qh b/qcsrc/lib/log.qh index fb53baaca..2a94fcf09 100644 --- a/qcsrc/lib/log.qh +++ b/qcsrc/lib/log.qh @@ -37,16 +37,16 @@ void print_assertfailed_fatal(string expr); // would be nice if __FUNC__ could be concatenated at compile time #if 0 // less work, bigger binary - #define __SOURCELOC__ (sprintf("^7%s^9(^9"__FILE__"^7:^9"STR(__LINE__)"^7)", __FUNC__)) + #define __SOURCELOC__ (sprintf("^7%s^9(^9"__FILE__"^7:^9"STR(__LINE__)"^7)\n", __FUNC__)) #else - #define __SOURCELOC__ (sprintf("^7%s^9(^9%s^7:^9%s^7)", __FUNC__, __FILE__, STR(__LINE__))) + #define __SOURCELOC__ (sprintf("^7%s^9(^9%s^7:^9%s^7)\n", __FUNC__, __FILE__, STR(__LINE__))) #endif -#define _LOG_PREFIX(level) strcat("^9[::^7", PROGNAME, "^9::", level, "^9] ") -#define _LOG_HEADER(level) strcat(_LOG_PREFIX(level), __SOURCELOC__, "\n") +#define _LOG_HEADER(level, full) strcat("^9[::^7", PROGNAME, "^9::", level, "^9] ", ((full) ? __SOURCELOC__ : "")) + #define _LOG(func_header, level, func_msg, s) \ MACRO_BEGIN \ - func_header(autocvar_developer > 0 ? _LOG_HEADER(level) : _LOG_PREFIX(level)); \ + func_header(_LOG_HEADER(level, autocvar_developer > 0)); \ func_msg(strcat("^7", s, "\n")); \ MACRO_END @@ -66,8 +66,7 @@ void print_assertfailed_fatal(string expr); #define LOG_INFOF(...) _LOG_INFO(sprintf(__VA_ARGS__)) #define _LOG_INFO(s) \ MACRO_BEGIN \ - if (autocvar_developer > 1) print(_LOG_HEADER("^5INFO")); \ - else if (autocvar_developer > 0) print(_LOG_PREFIX("^5INFO")); \ + if (autocvar_developer > 0) print(_LOG_HEADER("^5INFO", autocvar_developer > 1)); \ string __s = s; \ print("^7", __s); \ /* TODO: unconditionally add a newline when possible */ \