From 2efc55c68ee1bd571d9e49057d8326471b60e9d7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 3 Dec 2007 18:56:33 +0000 Subject: [PATCH] Don't call g_get_language_names() per-key. (#500638, Michael Meeks) 2007-12-03 Matthias Clasen * glib/gkeyfile.c: Don't call g_get_language_names() per-key. (#500638, Michael Meeks) svn path=/trunk/; revision=6023 --- ChangeLog | 5 +++++ glib/gkeyfile.c | 23 ++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 16b0a95ea..f19faee5a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-12-03 Matthias Clasen + + * glib/gkeyfile.c: Don't call g_get_language_names() per-key. + (#500638, Michael Meeks) + 2007-12-03 Marco Barisione * glib/gregex.c: diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c index ac7e495c0..725d4be34 100644 --- a/glib/gkeyfile.c +++ b/glib/gkeyfile.c @@ -81,6 +81,8 @@ struct _GKeyFile gchar list_separator; GKeyFileFlags flags; + + gchar **locales; }; typedef struct _GKeyFileKeyValuePair GKeyFileKeyValuePair; @@ -206,6 +208,7 @@ g_key_file_init (GKeyFile *key_file) key_file->approximate_size = 0; key_file->list_separator = ';'; key_file->flags = 0; + key_file->locales = g_strdupv ((gchar **)g_get_language_names ()); } static void @@ -213,8 +216,17 @@ g_key_file_clear (GKeyFile *key_file) { GList *tmp, *group_node; + if (key_file->locales) + { + g_strfreev (key_file->locales); + key_file->locales = NULL; + } + if (key_file->parse_buffer) - g_string_free (key_file->parse_buffer, TRUE); + { + g_string_free (key_file->parse_buffer, TRUE); + key_file->parse_buffer = NULL; + } tmp = key_file->groups; while (tmp != NULL) @@ -698,17 +710,14 @@ static gboolean g_key_file_locale_is_interesting (GKeyFile *key_file, const gchar *locale) { - const gchar * const * current_locales; gsize i; if (key_file->flags & G_KEY_FILE_KEEP_TRANSLATIONS) return TRUE; - current_locales = g_get_language_names (); - - for (i = 0; current_locales[i] != NULL; i++) + for (i = 0; key_file->locales[i] != NULL; i++) { - if (g_ascii_strcasecmp (current_locales[i], locale) == 0) + if (g_ascii_strcasecmp (key_file->locales[i], locale) == 0) return TRUE; } @@ -2999,7 +3008,7 @@ g_key_file_add_group (GKeyFile *key_file, if (key_file->start_group == NULL) key_file->start_group = group; - g_hash_table_insert (key_file->group_hash, group->name, group); + g_hash_table_insert (key_file->group_hash, (gpointer)group->name, group); } static void