journalctl: don't convert between strv/Set for each log line
If output fields are specified, let's store this in a Set right-away, instead of converting between strv and Set again and again for each line. This is not only faster, but also simpler and shorter.
This commit is contained in:
@@ -129,7 +129,7 @@ static const char *arg_namespace = NULL;
|
||||
static uint64_t arg_vacuum_size = 0;
|
||||
static uint64_t arg_vacuum_n_files = 0;
|
||||
static usec_t arg_vacuum_time = 0;
|
||||
static char **arg_output_fields = NULL;
|
||||
static Set *arg_output_fields = NULL;
|
||||
static const char *arg_pattern = NULL;
|
||||
static pcre2_code *arg_compiled_pattern = NULL;
|
||||
static PatternCompileCase arg_case = PATTERN_COMPILE_CASE_AUTO;
|
||||
@@ -142,7 +142,7 @@ STATIC_DESTRUCTOR_REGISTER(arg_system_units, strv_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_user_units, strv_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_output_fields, strv_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_output_fields, set_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_compiled_pattern, pattern_freep);
|
||||
|
||||
static enum {
|
||||
@@ -1026,13 +1026,10 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
if (!v)
|
||||
return log_oom();
|
||||
|
||||
if (!arg_output_fields)
|
||||
arg_output_fields = TAKE_PTR(v);
|
||||
else {
|
||||
r = strv_extend_strv(&arg_output_fields, v, true);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
r = set_put_strdupv(&arg_output_fields, v);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1351,13 +1351,12 @@ int show_journal_entry(
|
||||
OutputMode mode,
|
||||
unsigned n_columns,
|
||||
OutputFlags flags,
|
||||
char **output_fields,
|
||||
Set *output_fields,
|
||||
const size_t highlight[2],
|
||||
bool *ellipsized,
|
||||
dual_timestamp *previous_ts,
|
||||
sd_id128_t *previous_boot_id) {
|
||||
|
||||
_cleanup_set_free_ Set *fields = NULL;
|
||||
dual_timestamp ts = DUAL_TIMESTAMP_NULL;
|
||||
sd_id128_t boot_id = SD_ID128_NULL;
|
||||
int r;
|
||||
@@ -1370,10 +1369,6 @@ int show_journal_entry(
|
||||
if (n_columns <= 0)
|
||||
n_columns = columns();
|
||||
|
||||
r = set_put_strdupv(&fields, output_fields);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = get_dual_timestamp(j, &ts, &boot_id);
|
||||
if (r == -EBADMSG) {
|
||||
log_debug_errno(r, "Skipping message we can't read: %m");
|
||||
@@ -1382,7 +1377,7 @@ int show_journal_entry(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get journal fields: %m");
|
||||
|
||||
r = output_funcs[mode](f, j, mode, n_columns, flags, fields, highlight, &ts, &boot_id, previous_ts, previous_boot_id);
|
||||
r = output_funcs[mode](f, j, mode, n_columns, flags, output_fields, highlight, &ts, &boot_id, previous_ts, previous_boot_id);
|
||||
|
||||
/* Store timestamp and boot ID for next iteration */
|
||||
*previous_ts = ts;
|
||||
|
||||
@@ -18,7 +18,7 @@ int show_journal_entry(
|
||||
OutputMode mode,
|
||||
unsigned n_columns,
|
||||
OutputFlags flags,
|
||||
char **output_fields,
|
||||
Set *output_fields,
|
||||
const size_t highlight[2],
|
||||
bool *ellipsized,
|
||||
dual_timestamp *previous_ts,
|
||||
|
||||
Reference in New Issue
Block a user