mirror of
https://github.com/systemd/systemd
synced 2024-09-20 00:21:55 +00:00
sd-journal: drop redundant re-reading of entry array object
This effectively reverts e562f13158
.
In the loop of the generic_array_bisect(), the offset of the entry array
object is unchanged, the object is read at the beginning of the loop, and
we do not read any other entry array object. Hence, it is not necessary to
re-read the object every time we use the object.
This commit is contained in:
parent
12c2560997
commit
f6548f053d
|
@ -2877,8 +2877,8 @@ enum {
|
||||||
|
|
||||||
static int generic_array_bisect_one(
|
static int generic_array_bisect_one(
|
||||||
JournalFile *f,
|
JournalFile *f,
|
||||||
uint64_t a, /* offset of entry array object. */
|
Object *array, /* entry array object */
|
||||||
uint64_t i, /* index of the entry item we will test. */
|
uint64_t i, /* index of the entry item in the array we will test. */
|
||||||
uint64_t needle,
|
uint64_t needle,
|
||||||
int (*test_object)(JournalFile *f, uint64_t p, uint64_t needle),
|
int (*test_object)(JournalFile *f, uint64_t p, uint64_t needle),
|
||||||
direction_t direction,
|
direction_t direction,
|
||||||
|
@ -2886,21 +2886,17 @@ static int generic_array_bisect_one(
|
||||||
uint64_t *right,
|
uint64_t *right,
|
||||||
uint64_t *ret_offset) {
|
uint64_t *ret_offset) {
|
||||||
|
|
||||||
Object *array;
|
|
||||||
uint64_t p;
|
uint64_t p;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(f);
|
assert(f);
|
||||||
|
assert(array);
|
||||||
assert(test_object);
|
assert(test_object);
|
||||||
assert(left);
|
assert(left);
|
||||||
assert(right);
|
assert(right);
|
||||||
assert(*left <= i);
|
assert(*left <= i);
|
||||||
assert(i <= *right);
|
assert(i <= *right);
|
||||||
|
|
||||||
r = journal_file_move_to_object(f, OBJECT_ENTRY_ARRAY, a, &array);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
p = journal_file_entry_array_item(f, array, i);
|
p = journal_file_entry_array_item(f, array, i);
|
||||||
if (p <= 0)
|
if (p <= 0)
|
||||||
r = -EBADMSG;
|
r = -EBADMSG;
|
||||||
|
@ -2998,7 +2994,7 @@ static int generic_array_bisect(
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
right--;
|
right--;
|
||||||
r = generic_array_bisect_one(f, a, right, needle, test_object, direction, &left, &right, &lp);
|
r = generic_array_bisect_one(f, array, right, needle, test_object, direction, &left, &right, &lp);
|
||||||
if (r == -ENOANO) {
|
if (r == -ENOANO) {
|
||||||
n = right;
|
n = right;
|
||||||
continue;
|
continue;
|
||||||
|
@ -3012,13 +3008,13 @@ static int generic_array_bisect(
|
||||||
* neighbors of the last index we looked at. */
|
* neighbors of the last index we looked at. */
|
||||||
|
|
||||||
if (last_index > 0 && last_index - 1 < right) {
|
if (last_index > 0 && last_index - 1 < right) {
|
||||||
r = generic_array_bisect_one(f, a, last_index - 1, needle, test_object, direction, &left, &right, NULL);
|
r = generic_array_bisect_one(f, array, last_index - 1, needle, test_object, direction, &left, &right, NULL);
|
||||||
if (r < 0 && r != -ENOANO)
|
if (r < 0 && r != -ENOANO)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last_index < right) {
|
if (last_index < right) {
|
||||||
r = generic_array_bisect_one(f, a, last_index + 1, needle, test_object, direction, &left, &right, NULL);
|
r = generic_array_bisect_one(f, array, last_index + 1, needle, test_object, direction, &left, &right, NULL);
|
||||||
if (r < 0 && r != -ENOANO)
|
if (r < 0 && r != -ENOANO)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -3035,7 +3031,7 @@ static int generic_array_bisect(
|
||||||
assert(left < right);
|
assert(left < right);
|
||||||
i = (left + right) / 2;
|
i = (left + right) / 2;
|
||||||
|
|
||||||
r = generic_array_bisect_one(f, a, i, needle, test_object, direction, &left, &right, NULL);
|
r = generic_array_bisect_one(f, array, i, needle, test_object, direction, &left, &right, NULL);
|
||||||
if (r < 0 && r != -ENOANO)
|
if (r < 0 && r != -ENOANO)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -3065,10 +3061,6 @@ found:
|
||||||
if (subtract_one && t == 0 && i == 0)
|
if (subtract_one && t == 0 && i == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
r = journal_file_move_to_object(f, OBJECT_ENTRY_ARRAY, a, &array);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
p = journal_file_entry_array_item(f, array, 0);
|
p = journal_file_entry_array_item(f, array, 0);
|
||||||
if (p <= 0)
|
if (p <= 0)
|
||||||
return -EBADMSG;
|
return -EBADMSG;
|
||||||
|
|
Loading…
Reference in a new issue