evdev: don't execute snprintf if not gonna print

Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
This commit is contained in:
Konstantin Kharlamov 2019-01-12 02:15:20 +03:00
parent d9338b001c
commit 15e64b7b60
3 changed files with 16 additions and 2 deletions

View file

@ -713,6 +713,9 @@ evdev_log_msg(struct evdev_device *device,
va_list args;
char buf[1024];
if (!is_logged(evdev_libinput_context(device), priority))
return;
/* Anything info and above is user-visible, use the device name */
snprintf(buf,
sizeof(buf),
@ -741,6 +744,9 @@ evdev_log_msg_ratelimit(struct evdev_device *device,
enum ratelimit_state state;
if (!is_logged(evdev_libinput_context(device), priority))
return;
state = ratelimit_test(ratelimit);
if (state == RATELIMIT_EXCEEDED)
return;

View file

@ -404,6 +404,15 @@ typedef void (*libinput_source_dispatch_t)(void *data);
#define log_bug_libinput_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__)
#define log_bug_client_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__)
static inline bool
is_logged(const struct libinput *libinput,
enum libinput_log_priority priority)
{
return libinput->log_handler &&
libinput->log_priority <= priority;
}
void
log_msg_ratelimit(struct libinput *libinput,
struct ratelimit *ratelimit,

View file

@ -262,8 +262,7 @@ log_msg_va(struct libinput *libinput,
const char *format,
va_list args)
{
if (libinput->log_handler &&
libinput->log_priority <= priority)
if (is_logged(libinput, priority))
libinput->log_handler(libinput, priority, format, args);
}