From a3be2839e5da1ba780b63a0956c44c18c51c1343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 9 Feb 2019 16:58:08 +0100 Subject: [PATCH] module/i3: avoid calling json_object_get_int() multiple times --- modules/i3.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/i3.c b/modules/i3.c index 6e7fa75..c672ae0 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -445,8 +445,8 @@ handle_window_event(struct private *m, const struct json_object *json) free(ws->window.title); ws->window.title = strdup(json_object_get_string(name)); - const struct json_object *pid = json_object_object_get(container, "pid"); - if (pid == NULL || !json_object_is_type(pid, json_type_int)) { + const struct json_object *pid_node = json_object_object_get(container, "pid"); + if (pid_node == NULL || !json_object_is_type(pid_node, json_type_int)) { LOG_ERR( "'window' event (%s) did not contain a 'container.pid' integer value", change_str); @@ -454,8 +454,9 @@ handle_window_event(struct private *m, const struct json_object *json) } /* If PID has changed, update application name from /proc//comm */ - if (ws->window.pid != json_object_get_int(pid)) { - ws->window.pid = json_object_get_int(pid); + pid_t pid = json_object_get_int(pid_node); + if (ws->window.pid != pid) { + ws->window.pid = pid; char path[64]; snprintf(path, sizeof(path), "/proc/%u/comm", ws->window.pid);