]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Optimize _LOG_HEADER to avoid bloating compilation output files and reduce program...
authorterencehill <piuntn@gmail.com>
Thu, 21 Sep 2023 17:46:34 +0000 (19:46 +0200)
committerbones_was_here <bones_was_here@xonotic.au>
Tue, 12 Mar 2024 02:33:14 +0000 (12:33 +1000)
qcsrc/lib/log.qh

index fb53baaca92ff147cce69a51b3883b8001eb8235..2a94fcf09739876f5273f4a70514e1a1662c1b6b 100644 (file)
@@ -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 */ \