[systemd-commits] src/journal

Michal Schmidt michich at kemper.freedesktop.org
Fri Dec 19 07:23:21 PST 2014


 src/journal/sd-journal.c |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

New commits:
commit b29ddfcb389127cf00ab41447a721e479fe15713
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Fri Dec 19 14:42:55 2014 +0100

    journal: make next_with_matches() always use f->current_offset
    
    next_with_matches() is odd in that its "unit64_t *offset" parameter is
    both input and output. In other it's purely for output.
    
    The function is called from two places in next_beyond_location(). In
    both of them "&cp" is used as the argument and in both cases cp is
    guaranteed to equal f->current_offset.
    
    Let's just have next_with_matches() ignore "*offset" on input and
    operate with f->current_offset.
    
    I did not investigate why it is, but it makes my usual benchmark run
    reproducibly faster:
    
    $ time ./journalctl --since=2014-06-01 --until=2014-07-01 > /dev/null
    
    real    0m4.032s
    user    0m3.896s
    sys     0m0.135s
    
    (Compare to preceding commit, where real was 4.4s.)

diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 173f948..89cab37 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -697,23 +697,22 @@ static int next_with_matches(
                 Object **ret,
                 uint64_t *offset) {
 
-        uint64_t cp;
-
         assert(j);
         assert(f);
         assert(ret);
         assert(offset);
 
-        cp = *offset;
-
         /* No matches is easy. We simple advance the file
          * pointer by one. */
         if (!j->level0)
-                return journal_file_next_entry(f, cp, direction, ret, offset);
+                return journal_file_next_entry(f, f->current_offset, direction, ret, offset);
 
         /* If we have a match then we look for the next matching entry
          * with an offset at least one step larger */
-        return next_for_match(j, j->level0, f, direction == DIRECTION_DOWN ? cp+1 : cp-1, direction, ret, offset);
+        return next_for_match(j, j->level0, f,
+                              direction == DIRECTION_DOWN ? f->current_offset + 1
+                                                          : f->current_offset - 1,
+                              direction, ret, offset);
 }
 
 static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direction) {
@@ -731,8 +730,6 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc
         f->last_n_entries = n_entries;
 
         if (f->last_direction == direction && f->current_offset > 0) {
-                cp = f->current_offset;
-
                 /* LOCATION_SEEK here means we did the work in a previous
                  * iteration and the current location already points to a
                  * candidate entry. */



More information about the systemd-commits mailing list