Skip to content

Commit b3423b8

Browse files
committed
lib: replace some fprintf by fputs in mlog()
In this spot, fprintf is about 13% slower.
1 parent e3cea0f commit b3423b8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/rfbl.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,19 +1065,22 @@ void mlog(unsigned int level, const char *fmt, ...)
10651065
va_end(args);
10661066
return;
10671067
} else if (g_logfp == nullptr) {
1068-
if (g_log_tty)
1069-
fprintf(stderr,
1070-
level <= LV_ERR ? "\e[1;31m" :
1071-
level <= LV_WARN ? "\e[31m" :
1072-
level <= LV_NOTICE ? "\e[1;37m" :
1073-
level == LV_DEBUG ? "\e[1;30m" : "");
1068+
if (g_log_tty) {
1069+
auto c = level <= LV_ERR ? "\e[1;31m" :
1070+
level <= LV_WARN ? "\e[31m" :
1071+
level <= LV_NOTICE ? "\e[1;37m" :
1072+
level == LV_DEBUG ? "\e[1;30m" : "";
1073+
if (*c != '\0')
1074+
fputs(c, stderr);
1075+
}
10741076
#if 0
10751077
fprintf(stderr, "[%f] ", std::chrono::duration<double>(tp_now() - decltype(tp_now()){}).count());
10761078
#endif
10771079
vfprintf(stderr, fmt, args);
10781080
if (g_log_tty)
1079-
fprintf(stderr, "\e[0m");
1080-
fputc('\n', stderr);
1081+
fputs("\e[0m\n", stderr);
1082+
else
1083+
fputc('\n', stderr);
10811084
va_end(args);
10821085
return;
10831086
}

0 commit comments

Comments
 (0)