]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: optimize loop in path_spec_fd_event()
authorLennart Poettering <lennart@poettering.net>
Tue, 25 May 2021 21:09:42 +0000 (23:09 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 25 May 2021 21:14:34 +0000 (23:14 +0200)
Let's avoid the whole loop if it can never match

src/core/path.c

index 355f6c645d49d075fa54fee7f49bc2d469e05136..8f2971a4e15a4572019a18067a00ed7e8289cd79 100644 (file)
@@ -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) {