evdev: don't execute snprintf if not gonna print
authorKonstantin Kharlamov <Hi-Angel@yandex.ru>
Fri, 11 Jan 2019 23:15:20 +0000 (02:15 +0300)
committerKonstantin Kharlamov <Hi-Angel@yandex.ru>
Thu, 17 Jan 2019 10:08:14 +0000 (13:08 +0300)
Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
src/evdev.h
src/libinput-private.h
src/libinput.c

index cb7653449062207f5c802ebfd60b4413f492ff96..3a613eb54e6be04334674056d2d171e81b513f8e 100644 (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;
index 34cf90dfe73d157a6ee9977eeff005a6e466819c..ad92cde8b2dcdccffc79c9e29d2dd10b8bca1eda 100644 (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,
index 01f53974074d44dc4b8febb181394d8eda445029..c17cc1af85eaa3f54a8513dc16d32a6d316f1669 100644 (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);
 }