gkeyfile: Move allocation of value until after locale checks have passed

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 <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2021-03-14 14:11:34 +00:00
parent 6c70d30f07
commit 5a38dc79f0

View File

@ -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? /* Is this key a translation? If so, is it one that we care about?
*/ */
locale = key_get_locale (key); 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 = g_slice_new (GKeyFileKeyValuePair);
pair->key = g_steal_pointer (&key); 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_key_file_add_key_value_pair (key_file, key_file->current_group, pair);
} }
g_free (key); g_free (key);
g_free (value);
g_free (locale); g_free (locale);
} }