[systemd-devel] [PATCH 14/17] journal: change direction tests to use the same convention (cp </> np)
Zbigniew Jędrzejewski-Szmek
zbyszek at in.waw.pl
Fri Jun 7 21:22:46 PDT 2013
The order was different in various places, which makes it harder to
read to code. Also consistently use ternany for all direction checks.
Remove one free(NULL).
---
src/journal/sd-journal.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index d5b790b..751318f 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -163,7 +163,7 @@ static bool same_field(const void *_a, size_t s, const void *_b, size_t t) {
return true;
}
- return true;
+ assert_not_reached("\"=\" not found");
}
static Match *match_new(Match *p, MatchType t) {
@@ -371,10 +371,8 @@ static char *match_make_string(Match *m) {
p = k;
enclose = true;
- } else {
- free(p);
+ } else
p = t;
- }
}
if (enclose) {
@@ -587,11 +585,14 @@ static int next_for_match(
if (r < 0)
return r;
else if (r > 0) {
- if (np == 0 || (direction == DIRECTION_DOWN ? np > cp : np < cp))
+ if (np == 0 || (direction == DIRECTION_DOWN ? cp < np : cp > np))
np = cp;
}
}
+ if (np == 0)
+ return 0;
+
} else if (m->type == MATCH_AND_TERM) {
Match *i, *last_moved;
@@ -624,8 +625,7 @@ static int next_for_match(
}
}
- if (np == 0)
- return 0;
+ assert(np > 0);
r = journal_file_move_to_object(f, OBJECT_ENTRY, np, &n);
if (r < 0)
@@ -730,7 +730,7 @@ static int find_location_for_match(
if (r <= 0)
return r;
- if (np == 0 || (direction == DIRECTION_DOWN ? np < cp : np > cp))
+ if (np == 0 || (direction == DIRECTION_DOWN ? cp > np : cp < np))
np = cp;
}
@@ -826,7 +826,7 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc
return r;
}
- /* OK, we found the spot, now let's advance until to an entry
+ /* OK, we found the spot, now let's advance until an entry
* that is actually different from what we were previously
* looking at. This is necessary to handle entries which exist
* in two (or more) journal files, and which shall all be
@@ -888,10 +888,7 @@ static int real_journal_next(sd_journal *j, direction_t direction) {
k = compare_entry_order(f, o, new_file, new_offset);
- if (direction == DIRECTION_DOWN)
- found = k < 0;
- else
- found = k > 0;
+ found = direction == DIRECTION_DOWN ? k < 0 : k > 0;
}
if (found) {
--
1.8.2.562.g931e949
More information about the systemd-devel
mailing list