mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-20 02:52:46 +08:00
Turn debug() into a macro
A large portion of time was spent constructing strings and passing them to debug(). Turn debug into a macro so that the strings are only constructed if they're going to be printed.
This commit is contained in:
parent
a99eecfad8
commit
457213a768
|
@ -554,12 +554,6 @@ bool should_suppress_stderr_for_tests() {
|
|||
return program_name && !wcscmp(program_name, TESTS_PROGRAM_NAME);
|
||||
}
|
||||
|
||||
/// Return true if we should emit a `debug()` message. This used to call
|
||||
/// `should_suppress_stderr_for_tests()`. It no longer does so because it can suppress legitimate
|
||||
/// errors we want to see if things go wrong. Too, calling that function is no longer necessary, if
|
||||
/// it ever was, to suppress unwanted diagnostic output that might confuse people running `make
|
||||
/// test`.
|
||||
static bool should_debug(int level) { return level <= debug_level; }
|
||||
|
||||
static void debug_shared(const wchar_t level, const wcstring &msg) {
|
||||
pid_t current_pid = getpid();
|
||||
|
@ -573,8 +567,7 @@ static void debug_shared(const wchar_t level, const wcstring &msg) {
|
|||
}
|
||||
|
||||
static wchar_t level_char[] = {L'E', L'W', L'2', L'3', L'4', L'5'};
|
||||
void __attribute__((noinline)) debug(int level, const wchar_t *msg, ...) {
|
||||
if (!should_debug(level)) return;
|
||||
void __attribute__((noinline)) debug_impl(int level, const wchar_t *msg, ...) {
|
||||
int errno_old = errno;
|
||||
va_list va;
|
||||
va_start(va, msg);
|
||||
|
@ -588,7 +581,7 @@ void __attribute__((noinline)) debug(int level, const wchar_t *msg, ...) {
|
|||
errno = errno_old;
|
||||
}
|
||||
|
||||
void __attribute__((noinline)) debug(int level, const char *msg, ...) {
|
||||
void __attribute__((noinline)) debug_impl(int level, const char *msg, ...) {
|
||||
if (!should_debug(level)) return;
|
||||
int errno_old = errno;
|
||||
char local_msg[512];
|
||||
|
|
19
src/common.h
19
src/common.h
|
@ -159,9 +159,20 @@ enum selection_direction_t {
|
|||
///
|
||||
/// will print the string 'fish: Pi = 3.141', given that debug_level is 1 or higher, and that
|
||||
/// program_name is 'fish'.
|
||||
void __attribute__((noinline)) debug(int level, const char *msg, ...)
|
||||
void __attribute__((noinline)) debug_impl(int level, const char *msg, ...)
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
void __attribute__((noinline)) debug(int level, const wchar_t *msg, ...);
|
||||
void __attribute__((noinline)) debug_impl(int level, const wchar_t *msg, ...);
|
||||
|
||||
/// The verbosity level of fish. If a call to debug has a severity level higher than \c debug_level,
|
||||
/// it will not be printed.
|
||||
extern int debug_level;
|
||||
|
||||
inline bool should_debug(int level) { return level <= debug_level; }
|
||||
|
||||
#define debug(level, ...) \
|
||||
do { \
|
||||
if (should_debug((level))) debug_impl((level), __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
/// Exits without invoking destructors (via _exit), useful for code after fork.
|
||||
[[noreturn]] void exit_without_destructors(int code);
|
||||
|
@ -179,10 +190,6 @@ extern wchar_t omitted_newline_char;
|
|||
/// Character used for the silent mode of the read command
|
||||
extern wchar_t obfuscation_read_char;
|
||||
|
||||
/// The verbosity level of fish. If a call to debug has a severity level higher than \c debug_level,
|
||||
/// it will not be printed.
|
||||
extern int debug_level;
|
||||
|
||||
/// How many stack frames to show when a debug() call is made.
|
||||
extern int debug_stack_frames;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user