sd-journal: reduce number of calls generic_array_bisect_plus_one()

If the first call of generic_array_bisect_plus_one() provides the same
offset, then it is not necessary to call the next one, as we already
know the entry object is also liked to the input data object.

Also, this make the function reuse the object returned by
generic_array_bisect_plus_one().

No functional change, just optimization.
This commit is contained in:
Yu Watanabe 2023-09-28 04:15:04 +09:00
parent 20c45e5784
commit 80f96c0ce1

View File

@ -3542,7 +3542,7 @@ int journal_file_move_to_entry_by_monotonic_for_data(
uint64_t *ret_offset) {
uint64_t z, entry_offset, entry_array_offset, n_entries;
Object *o;
Object *o, *entry;
int r;
assert(f);
@ -3570,10 +3570,12 @@ int journal_file_move_to_entry_by_monotonic_for_data(
if (r <= 0)
return r;
/* And now, continue seeking until we find an entry that
* exists in both bisection arrays */
/* And now, continue seeking until we find an entry that exists in both bisection arrays. */
for (;;) {
uint64_t p, q;
uint64_t p;
/* The journal entry found by the above bisect_plus_one() may not have the specified data,
* that is, it may not be linked in the data object. So, we need to check that. */
r = generic_array_bisect_plus_one(f,
entry_offset,
@ -3582,9 +3584,15 @@ int journal_file_move_to_entry_by_monotonic_for_data(
z,
test_object_offset,
direction,
NULL, &p);
ret_object ? &entry : NULL, &p);
if (r <= 0)
return r;
if (p == z)
break; /* The journal entry has the specified data. Yay! */
/* If the entry does not have the data, then move to the next (or previous, depends on the
* 'direction') entry linked to the data object. But, the next entry may be in another boot.
* So, we need to check that the entry has the matching boot ID. */
r = generic_array_bisect_plus_one(f,
le64toh(o->data.entry_offset),
@ -3593,28 +3601,22 @@ int journal_file_move_to_entry_by_monotonic_for_data(
p,
test_object_offset,
direction,
NULL, &q);
ret_object ? &entry : NULL, &z);
if (r <= 0)
return r;
if (p == z)
break; /* The journal entry has the specified boot ID. Yay! */
if (p == q) {
if (ret_object) {
r = journal_file_move_to_object(f, OBJECT_ENTRY, q, ret_object);
if (r < 0)
return r;
/* If not, let's try to the next entry... */
}
if (ret_object)
*ret_object = entry;
if (ret_offset)
*ret_offset = q;
*ret_offset = z;
return 1;
}
z = q;
}
}
int journal_file_move_to_entry_by_seqnum_for_data(
JournalFile *f,
Object *d,