From 15e64b7b60af56a31006bd4742dab3b275d47108 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sat, 12 Jan 2019 02:15:20 +0300 Subject: [PATCH] evdev: don't execute snprintf if not gonna print Signed-off-by: Konstantin Kharlamov --- src/evdev.h | 6 ++++++ src/libinput-private.h | 9 +++++++++ src/libinput.c | 3 +-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/evdev.h b/src/evdev.h index cb765344..3a613eb5 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -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; diff --git a/src/libinput-private.h b/src/libinput-private.h index 34cf90df..ad92cde8 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -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, diff --git a/src/libinput.c b/src/libinput.c index 01f53974..c17cc1af 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -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); }