From 403f6e3081150f402f90e18454a4c4658f72c84b Mon Sep 17 00:00:00 2001 From: Alex Kompel Date: Tue, 9 Jun 2015 08:53:21 -0700 Subject: [PATCH] win32_gui: improve logDebug performance --- win/win32/mswproc.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index 3bfa23b1d..f4eb6a0fb 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -32,6 +32,7 @@ #define NHTRACE_LOG "nhtrace.log" #ifdef _DEBUG +static FILE* _s_debugfp = NULL; extern void logDebug(const char *fmt, ...); #else void @@ -131,15 +132,14 @@ mswin_init_nhwindows(int *argc, char **argv) UNREFERENCED_PARAMETER(argc); UNREFERENCED_PARAMETER(argv); - logDebug("mswin_init_nhwindows()\n"); - #ifdef _DEBUG - if (showdebug(NHTRACE_LOG)) { + if (showdebug(NHTRACE_LOG) && !_s_debugfp) { /* truncate trace file */ - FILE *dfp = fopen(NHTRACE_LOG, "w"); - fclose(dfp); + _s_debugfp = fopen(NHTRACE_LOG, "w"); } #endif + logDebug("mswin_init_nhwindows()\n"); + mswin_nh_input_init(); /* set it to WIN_ERR so we can detect attempts to @@ -2198,20 +2198,15 @@ mswin_popup_destroy(HWND hWnd) void logDebug(const char *fmt, ...) { - FILE *dfp; + va_list args; - if (!showdebug(NHTRACE_LOG)) + if (!showdebug(NHTRACE_LOG) || !_s_debugfp) return; - dfp = fopen(NHTRACE_LOG, "a"); - if (dfp) { - va_list args; - - va_start(args, fmt); - vfprintf(dfp, fmt, args); - va_end(args); - fclose(dfp); - } + va_start(args, fmt); + vfprintf(_s_debugfp, fmt, args); + va_end(args); + fflush(_s_debugfp); } #endif