diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-10-12 11:54:36 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-10-12 20:25:20 +0200 |
commit | aa598ba5b63b70273d6295fce3cb8c304716a205 (patch) | |
tree | 4f6a21d4efb5a63a4f5de9e07a5f9abbaa1728ed /src/journal | |
parent | 202fd896e516bbd7379bf2e2bcc224d3ec2356cd (diff) |
journal: split out array index inc/dec code into a new call bump_array_index()
This allows us to share a bit more code between journal_file_next_entry() and
journal_file_next_entry_for_data().
Diffstat (limited to 'src/journal')
-rw-r--r-- | src/journal/journal-file.c | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 953f4e5ce6..8e47ebb944 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -2484,6 +2484,25 @@ int journal_file_compare_locations(JournalFile *af, JournalFile *bf) { return 0; } +static int bump_array_index(uint64_t *i, direction_t direction, uint64_t n) { + + /* Increase or decrease the specified index, in the right direction. */ + + if (direction == DIRECTION_DOWN) { + if (*i >= n - 1) + return 0; + + (*i) ++; + } else { + if (*i <= 0) + return 0; + + (*i) --; + } + + return 1; +} + int journal_file_next_entry( JournalFile *f, uint64_t p, @@ -2514,17 +2533,9 @@ int journal_file_next_entry( if (r <= 0) return r; - if (direction == DIRECTION_DOWN) { - if (i >= n - 1) - return 0; - - i++; - } else { - if (i <= 0) - return 0; - - i--; - } + r = bump_array_index(&i, direction, n); + if (r <= 0) + return r; } /* And jump to it */ @@ -2594,18 +2605,9 @@ int journal_file_next_entry_for_data( if (r <= 0) return r; - if (direction == DIRECTION_DOWN) { - if (i >= n - 1) - return 0; - - i++; - } else { - if (i <= 0) - return 0; - - i--; - } - + r = bump_array_index(&i, direction, n); + if (r <= 0) + return r; } return generic_array_get_plus_one(f, |