diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-01-19 11:35:36 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-01-20 21:46:01 +0100 |
commit | c5da14cd59e51d704c0fcf1d34798198ba51a5bc (patch) | |
tree | 315ab4fde15c85d306d5ea01b8a38f1b5ff6c466 | |
parent | 8ba814df255e5b65c36048355b22f757a0ccb6cb (diff) | |
download | systemd-c5da14cd59e51d704c0fcf1d34798198ba51a5bc.tar.gz |
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.
-rw-r--r-- | src/journal/journalctl.c | 15 | ||||
-rw-r--r-- | src/shared/logs-show.c | 9 | ||||
-rw-r--r-- | src/shared/logs-show.h | 2 |
3 files changed, 9 insertions, 17 deletions
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index dd28517924..b2883ff177 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -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; } diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 9f51e1ea74..352f389ff8 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -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; diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h index 0800b55c03..a15bda6886 100644 --- a/src/shared/logs-show.h +++ b/src/shared/logs-show.h @@ -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, |