From 1e59254ac2c7203b8c1be5c8120af14abf113a86 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 7 Aug 2024 11:20:39 +0900 Subject: [PATCH] sd-journal: swap condition to reduce indentation No functional change, just refactoring. --- src/libsystemd/sd-journal/sd-journal.c | 74 +++++++++++++------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c index 6eac5da5b91..01db11b4028 100644 --- a/src/libsystemd/sd-journal/sd-journal.c +++ b/src/libsystemd/sd-journal/sd-journal.c @@ -937,44 +937,44 @@ static int find_location_with_matches( assert(ret); assert(offset); - if (!j->level0) { - /* No matches is simple */ - - if (j->current_location.type == LOCATION_HEAD) - return direction == DIRECTION_DOWN ? journal_file_next_entry(f, 0, DIRECTION_DOWN, ret, offset) : 0; - if (j->current_location.type == LOCATION_TAIL) - return direction == DIRECTION_UP ? journal_file_next_entry(f, 0, DIRECTION_UP, ret, offset) : 0; - if (j->current_location.seqnum_set && sd_id128_equal(j->current_location.seqnum_id, f->header->seqnum_id)) - return journal_file_move_to_entry_by_seqnum(f, j->current_location.seqnum, direction, ret, offset); - if (j->current_location.monotonic_set) { - r = journal_file_move_to_entry_by_monotonic(f, j->current_location.boot_id, j->current_location.monotonic, direction, ret, offset); - if (r != 0) - return r; - - /* If not found, fall back to realtime if set, or go to the first entry of the next boot - * (or the last entry of the previous boot when DIRECTION_UP). */ - } - if (j->current_location.realtime_set) - return journal_file_move_to_entry_by_realtime(f, j->current_location.realtime, direction, ret, offset); - - if (j->current_location.monotonic_set) { - uint64_t p = 0; - - /* If not found in the above, first move to the last (or first when DIRECTION_UP) entry for the boot. */ - r = journal_file_move_to_entry_by_monotonic(f, j->current_location.boot_id, - direction == DIRECTION_DOWN ? USEC_INFINITY : 0, - direction == DIRECTION_DOWN ? DIRECTION_UP : DIRECTION_DOWN, - NULL, &p); - if (r <= 0) - return r; - - /* Then, move to the next or previous boot. */ - return journal_file_next_entry(f, p, direction, ret, offset); - } - - return journal_file_next_entry(f, 0, direction, ret, offset); - } else + if (j->level0) return find_location_for_match(j, j->level0, f, direction, ret, offset); + + /* No matches is simple */ + + if (j->current_location.type == LOCATION_HEAD) + return direction == DIRECTION_DOWN ? journal_file_next_entry(f, 0, DIRECTION_DOWN, ret, offset) : 0; + if (j->current_location.type == LOCATION_TAIL) + return direction == DIRECTION_UP ? journal_file_next_entry(f, 0, DIRECTION_UP, ret, offset) : 0; + if (j->current_location.seqnum_set && sd_id128_equal(j->current_location.seqnum_id, f->header->seqnum_id)) + return journal_file_move_to_entry_by_seqnum(f, j->current_location.seqnum, direction, ret, offset); + if (j->current_location.monotonic_set) { + r = journal_file_move_to_entry_by_monotonic(f, j->current_location.boot_id, j->current_location.monotonic, direction, ret, offset); + if (r != 0) + return r; + + /* If not found, fall back to realtime if set, or go to the first entry of the next boot + * (or the last entry of the previous boot when DIRECTION_UP). */ + } + if (j->current_location.realtime_set) + return journal_file_move_to_entry_by_realtime(f, j->current_location.realtime, direction, ret, offset); + + if (j->current_location.monotonic_set) { + uint64_t p = 0; + + /* If not found in the above, first move to the last (or first when DIRECTION_UP) entry for the boot. */ + r = journal_file_move_to_entry_by_monotonic(f, j->current_location.boot_id, + direction == DIRECTION_DOWN ? USEC_INFINITY : 0, + direction == DIRECTION_DOWN ? DIRECTION_UP : DIRECTION_DOWN, + NULL, &p); + if (r <= 0) + return r; + + /* Then, move to the next or previous boot. */ + return journal_file_next_entry(f, p, direction, ret, offset); + } + + return journal_file_next_entry(f, 0, direction, ret, offset); } static int next_with_matches(