From 5a38dc79f0161ca94b983702b8b1672e2447872d Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sun, 14 Mar 2021 14:11:34 +0000 Subject: [PATCH] gkeyfile: Move allocation of value until after locale checks have passed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids allocating a copy of the value in the case that it’s for a locale which is uninteresting. This should speed up parsing of key files with large numbers of translations, when only the translations for certain locales are wanted. Signed-off-by: Philip Withnall --- glib/gkeyfile.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c index 50ed5305d..9fd9c6eed 100644 --- a/glib/gkeyfile.c +++ b/glib/gkeyfile.c @@ -1420,8 +1420,6 @@ g_key_file_parse_key_value_pair (GKeyFile *key_file, } } - value = g_strndup (value_start, value_len); - /* Is this key a translation? If so, is it one that we care about? */ locale = key_get_locale (key); @@ -1432,13 +1430,12 @@ g_key_file_parse_key_value_pair (GKeyFile *key_file, pair = g_slice_new (GKeyFileKeyValuePair); pair->key = g_steal_pointer (&key); - pair->value = g_steal_pointer (&value); + pair->value = g_strndup (value_start, value_len); g_key_file_add_key_value_pair (key_file, key_file->current_group, pair); } g_free (key); - g_free (value); g_free (locale); }