]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #7042 from vcaputo/iteratedcache
authorLennart Poettering <lennart@poettering.net>
Thu, 1 Feb 2018 17:08:50 +0000 (18:08 +0100)
committerGitHub <noreply@github.com>
Thu, 1 Feb 2018 17:08:50 +0000 (18:08 +0100)
RFC: Optionally cache hashmap iterated results

1  2 
src/journal/sd-journal.c

diff --combined src/journal/sd-journal.c
index 6da7bf8e81a41068d339dd47985413337466d16a,384a9b1beeb43431cd1549aca084a7c4c2705b1e..a8812c9af83c0f4710f5dab33788ee8bb1c67457
@@@ -48,7 -48,6 +48,7 @@@
  #include "lookup3.h"
  #include "missing.h"
  #include "path-util.h"
 +#include "process-util.h"
  #include "replace-var.h"
  #include "stat-util.h"
  #include "stdio-util.h"
@@@ -820,15 -819,21 +820,21 @@@ static int next_beyond_location(sd_jour
  }
  
  static int real_journal_next(sd_journal *j, direction_t direction) {
-         JournalFile *f, *new_file = NULL;
-         Iterator i;
+         JournalFile *new_file = NULL;
+         unsigned i, n_files;
+         const void **files;
          Object *o;
          int r;
  
          assert_return(j, -EINVAL);
          assert_return(!journal_pid_changed(j), -ECHILD);
  
-         ORDERED_HASHMAP_FOREACH(f, j->files, i) {
+         r = iterated_cache_get(j->files_cache, NULL, &files, &n_files);
+         if (r < 0)
+                 return r;
+         for (i = 0; i < n_files; i++) {
+                 JournalFile *f = (JournalFile *)files[i];
                  bool found;
  
                  r = next_beyond_location(j, f, direction);
@@@ -1737,9 -1742,13 +1743,13 @@@ static sd_journal *journal_new(int flag
          }
  
          j->files = ordered_hashmap_new(&string_hash_ops);
+         if (!j->files)
+                 goto fail;
+         j->files_cache = ordered_hashmap_iterated_cache_new(j->files);
          j->directories_by_path = hashmap_new(&string_hash_ops);
          j->mmap = mmap_cache_new();
-         if (!j->files || !j->directories_by_path || !j->mmap)
+         if (!j->files_cache || !j->directories_by_path || !j->mmap)
                  goto fail;
  
          return j;
@@@ -1985,6 -1994,7 +1995,7 @@@ _public_ void sd_journal_close(sd_journ
          sd_journal_flush_matches(j);
  
          ordered_hashmap_free_with_destructor(j->files, journal_file_close);
+         iterated_cache_free(j->files_cache);
  
          while ((d = hashmap_first(j->directories_by_path)))
                  remove_directory(j, d);