]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl: don't convert between strv/Set for each log line
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Jan 2023 10:35:36 +0000 (11:35 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 20 Jan 2023 20:46:01 +0000 (21:46 +0100)
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.

src/journal/journalctl.c
src/shared/logs-show.c
src/shared/logs-show.h

index dd285179247fd4baaaae531a3cd0c1bd163b41fa..b2883ff177ba091f76c063e043c1bd47ed5e242f 100644 (file)
@@ -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;
                 }
 
index 9f51e1ea7420ecbfbe1b50261e26dcfa077b71f8..352f389ff8da24c1588f1dbf9ba494ac201adc6c 100644 (file)
@@ -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;
index 0800b55c03d10f0a6db9c6ef28b22ff30a06641e..a15bda688616933a37b39792164b3e8cb1d1deb2 100644 (file)
@@ -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,