]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mmap-cache: merge window_matches() and window_matches_fd()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 30 Sep 2023 02:32:38 +0000 (11:32 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 4 Oct 2023 10:53:27 +0000 (19:53 +0900)
Let's drop meaningless optimization, and always check if the window is
owned by the expected fd.

src/libsystemd/sd-journal/mmap-cache.c

index 7a3057c88408ce0111d1ee9e2b5b0965761cc77f..11b1abd8b7f388790bd83ae4ff7f7a945a049a23 100644 (file)
@@ -137,24 +137,16 @@ static Window* window_free(Window *w) {
         return mfree(w);
 }
 
-static bool window_matches(Window *w, uint64_t offset, size_t size) {
-        assert(w);
+static bool window_matches(Window *w, MMapFileDescriptor *f, uint64_t offset, size_t size) {
         assert(size > 0);
 
         return
+                w &&
+                f == w->fd &&
                 offset >= w->offset &&
                 offset + size <= w->offset + w->size;
 }
 
-static bool window_matches_fd(Window *w, MMapFileDescriptor *f, uint64_t offset, size_t size) {
-        assert(w);
-        assert(f);
-
-        return
-                w->fd == f &&
-                window_matches(w, offset, size);
-}
-
 static Window *window_add(MMapCache *m, MMapFileDescriptor *f, bool keep_always, uint64_t offset, size_t size, void *ptr) {
         Window *w;
 
@@ -272,7 +264,7 @@ static int try_context(
         if (!c->window)
                 return 0;
 
-        if (!window_matches_fd(c->window, f, offset, size)) {
+        if (!window_matches(c->window, f, offset, size)) {
 
                 /* Drop the reference to the window, since it's unnecessary now */
                 context_detach_window(f->cache, c);
@@ -310,7 +302,7 @@ static int find_mmap(
                 return -EIO;
 
         LIST_FOREACH(by_fd, w, f->windows)
-                if (window_matches(w, offset, size)) {
+                if (window_matches(w, f, offset, size)) {
                         found = w;
                         break;
                 }