diff options
author | Philip Withnall <pwithnall@endlessos.org> | 2022-12-29 17:38:04 +0000 |
---|---|---|
committer | Philip Withnall <pwithnall@endlessos.org> | 2023-01-18 12:15:47 +0000 |
commit | f068347b1419213be20e3647f5d4f1d505bdcba4 (patch) | |
tree | a5e9e3ee985ad25902b5f4777f8972f49303196d | |
parent | c28829fe87f62396563640d5a209ad249e8dfcf5 (diff) | |
download | glib-f068347b1419213be20e3647f5d4f1d505bdcba4.tar.gz |
gvariant: Factor out some common calls to g_variant_get_type_string()
When printing a `GVariant`.
This introduces no functional changes, but should speed things up a
little bit when printing out arrays.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
-rw-r--r-- | glib/gvariant.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/glib/gvariant.c b/glib/gvariant.c index 95904bd38..8f0c237db 100644 --- a/glib/gvariant.c +++ b/glib/gvariant.c @@ -2213,15 +2213,16 @@ g_variant_print_string (GVariant *value, GString *string, gboolean type_annotate) { + const gchar *value_type_string = g_variant_get_type_string (value); + if G_UNLIKELY (string == NULL) string = g_string_new (NULL); - switch (g_variant_classify (value)) + switch (value_type_string[0]) { case G_VARIANT_CLASS_MAYBE: if (type_annotate) - g_string_append_printf (string, "@%s ", - g_variant_get_type_string (value)); + g_string_append_printf (string, "@%s ", value_type_string); if (g_variant_n_children (value)) { @@ -2265,7 +2266,7 @@ g_variant_print_string (GVariant *value, * if the first two characters are 'ay' then it's a bytestring. * under certain conditions we print those as strings. */ - if (g_variant_get_type_string (value)[1] == 'y') + if (value_type_string[1] == 'y') { const gchar *str; gsize size; @@ -2307,7 +2308,7 @@ g_variant_print_string (GVariant *value, * dictionary entries (ie: a dictionary) so we print that * differently. */ - if (g_variant_get_type_string (value)[1] == '{') + if (value_type_string[1] == '{') /* dictionary */ { const gchar *comma = ""; @@ -2316,8 +2317,7 @@ g_variant_print_string (GVariant *value, if ((n = g_variant_n_children (value)) == 0) { if (type_annotate) - g_string_append_printf (string, "@%s ", - g_variant_get_type_string (value)); + g_string_append_printf (string, "@%s ", value_type_string); g_string_append (string, "{}"); break; } @@ -2353,8 +2353,7 @@ g_variant_print_string (GVariant *value, if ((n = g_variant_n_children (value)) == 0) { if (type_annotate) - g_string_append_printf (string, "@%s ", - g_variant_get_type_string (value)); + g_string_append_printf (string, "@%s ", value_type_string); g_string_append (string, "[]"); break; } |