[glib/wip/baedert/keyfile] keyfile: Delay calling g_get_language_names() until it's needed
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/baedert/keyfile] keyfile: Delay calling g_get_language_names() until it's needed
- Date: Wed, 30 Dec 2020 11:39:26 +0000 (UTC)
commit 037f1ce672a54c0ad62bd0dd72a64663c93c7f61
Author: Timm Bäder <mail baedert org>
Date: Tue Dec 29 08:35:36 2020 +0100
keyfile: Delay calling g_get_language_names() until it's needed
The g_get_languages() call is quite costly and often unneeded.
glib/gkeyfile.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c
index bbe638b74..8fc0322e8 100644
--- a/glib/gkeyfile.c
+++ b/glib/gkeyfile.c
@@ -510,6 +510,7 @@ struct _GKeyFile
GKeyFileFlags flags;
+ gboolean checked_locales;
gchar **locales;
gint ref_count; /* (atomic) */
@@ -635,7 +636,6 @@ g_key_file_init (GKeyFile *key_file)
key_file->parse_buffer = g_string_sized_new (128);
key_file->list_separator = ';';
key_file->flags = 0;
- key_file->locales = g_strdupv ((gchar **)g_get_language_names ());
}
static void
@@ -1232,6 +1232,12 @@ g_key_file_locale_is_interesting (GKeyFile *key_file,
if (key_file->flags & G_KEY_FILE_KEEP_TRANSLATIONS)
return TRUE;
+ if (!key_file->checked_locales && !key_file->locales)
+ {
+ key_file->locales = g_strdupv ((gchar **)g_get_language_names ());
+ key_file->checked_locales = TRUE;
+ }
+
for (i = 0; key_file->locales[i] != NULL; i++)
{
if (g_ascii_strcasecmp (key_file->locales[i], locale) == 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]