Optimize non-enabled calls to debug() by moving the if test before we do a function call.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@1994 4a71c877-e1ca-e34f-864e-861f7616d084
master
Per Inge Mathisen 2007-07-01 11:54:09 +00:00
parent bfb3775e83
commit 64c9ca9ecd
2 changed files with 13 additions and 15 deletions

View File

@ -36,7 +36,7 @@
char last_called_script_event[MAX_EVENT_NAME_LEN];
static debug_callback * callbackRegistry = NULL;
static BOOL enabled_debug_parts[LOG_LAST];
BOOL enabled_debug[LOG_LAST]; // global
/*
* This list _must_ match the enum in debug.h!
@ -188,10 +188,10 @@ void debug_init(void)
"list in debug.c!\n" );
exit(1);
}
memset( enabled_debug_parts, FALSE, sizeof(enabled_debug_parts) );
enabled_debug_parts[LOG_ERROR] = TRUE;
memset( enabled_debug, FALSE, sizeof(enabled_debug) );
enabled_debug[LOG_ERROR] = TRUE;
#ifdef DEBUG
enabled_debug_parts[LOG_WARNING] = TRUE;
enabled_debug[LOG_WARNING] = TRUE;
#endif
}
@ -246,16 +246,16 @@ BOOL debug_enable_switch(const char *str)
int part = code_part_from_str(str);
if (part != LOG_LAST) {
enabled_debug_parts[part] = !enabled_debug_parts[part];
enabled_debug[part] = !enabled_debug[part];
}
if (part == LOG_ALL) {
memset(enabled_debug_parts, TRUE, sizeof(enabled_debug_parts));
memset(enabled_debug, TRUE, sizeof(enabled_debug));
}
return (part != LOG_LAST);
}
void debug( code_part part, const char *str, ... )
void _debug( code_part part, const char *str, ... )
{
va_list ap;
static char inputBuffer[2][MAX_LEN_LOG_LINE];
@ -268,11 +268,6 @@ void debug( code_part part, const char *str, ... )
static unsigned int next = 2; /* next total to print update */
static unsigned int prev = 0; /* total on last update */
/* Not enabled debugging for this part? Punt! */
if (!enabled_debug_parts[part]) {
return;
}
va_start(ap, str);
vsnprintf( useInputBuffer1 ? inputBuffer[1] : inputBuffer[0], MAX_LEN_LOG_LINE, str, ap );
va_end(ap);

View File

@ -63,8 +63,8 @@ extern char last_called_script_event[MAX_EVENT_NAME_LEN];
* Arguments: ASSERT( condition, "Format string with variables: %d, %d", var1, var2 );
*/
#define ASSERT( expr, ... ) \
( (expr) ? (void)0 : (void)debug( LOG_ERROR, __VA_ARGS__ ) ); \
( (expr) ? (void)0 : (void)debug( LOG_ERROR, "Assert in Warzone: %s:%d : %s (%s), last script event: '%s'", \
( (expr) ? (void)0 : (void)_debug( LOG_ERROR, __VA_ARGS__ ) ); \
( (expr) ? (void)0 : (void)_debug( LOG_ERROR, "Assert in Warzone: %s:%d : %s (%s), last script event: '%s'", \
__FILE__, __LINE__, __FUNCTION__, (#expr), last_called_script_event ) ); \
assert( expr );
@ -119,6 +119,8 @@ typedef enum {
LOG_LAST /* _must_ be last! */
} code_part;
extern BOOL enabled_debug[LOG_LAST];
typedef void (*debug_callback_fn)(void**, const char*);
typedef void (*debug_callback_init)(void**);
typedef void (*debug_callback_exit)(void**);
@ -174,7 +176,8 @@ BOOL debug_enable_switch(const char *str);
* \param part Code part to associate with this message
* \param str printf style formatstring
*/
void debug( code_part part, const char *str, ...)
#define debug(part, ...) do { if (enabled_debug[part]) _debug(part, __VA_ARGS__); } while(0)
void _debug( code_part part, const char *str, ...)
wz__attribute((format (printf, 2, 3)) );
#endif