From d6d00b650f47f6db5f29eb273eaaef7ed71f61f1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 25 May 2021 23:09:42 +0200 Subject: [PATCH] core: optimize loop in path_spec_fd_event() Let's avoid the whole loop if it can never match --- src/core/path.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/path.c b/src/core/path.c index 355f6c645d4..8f2971a4e15 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -153,7 +153,8 @@ int path_spec_fd_event(PathSpec *s, uint32_t revents) { union inotify_event_buffer buffer; struct inotify_event *e; ssize_t l; - int r = 0; + + assert(s); if (revents != EPOLLIN) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), @@ -167,13 +168,12 @@ int path_spec_fd_event(PathSpec *s, uint32_t revents) { return log_error_errno(errno, "Failed to read inotify event: %m"); } - FOREACH_INOTIFY_EVENT(e, buffer, l) { - if (IN_SET(s->type, PATH_CHANGED, PATH_MODIFIED) && - s->primary_wd == e->wd) - r = 1; - } + if (IN_SET(s->type, PATH_CHANGED, PATH_MODIFIED)) + FOREACH_INOTIFY_EVENT(e, buffer, l) + if (s->primary_wd == e->wd) + return 1; - return r; + return 0; } static bool path_spec_check_good(PathSpec *s, bool initial, bool from_trigger_notify) {