[glib/wip/baedert/gparam: 4/5] keyfile: Only allocate group_hash if needed
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/baedert/gparam: 4/5] keyfile: Only allocate group_hash if needed
- Date: Thu, 31 Dec 2020 12:22:51 +0000 (UTC)
commit 18651e9933909811002f0d4fb5cb2c3361779d98
Author: Timm Bäder <mail baedert org>
Date: Thu Dec 31 11:58:50 2020 +0100
keyfile: Only allocate group_hash if needed
A keyfile with no groups (e.g. an empty one) does not need a hash table
for the groups.
glib/gkeyfile.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c
index 744c547b9..d1106f0f0 100644
--- a/glib/gkeyfile.c
+++ b/glib/gkeyfile.c
@@ -631,7 +631,7 @@ g_key_file_init (GKeyFile *key_file)
{
key_file->current_group = g_slice_new0 (GKeyFileGroup);
key_file->groups = g_list_prepend (NULL, key_file->current_group);
- key_file->group_hash = g_hash_table_new (g_str_hash, g_str_equal);
+ key_file->group_hash = NULL;
key_file->start_group = NULL;
key_file->parse_buffer = NULL;
key_file->list_separator = ';';
@@ -3837,6 +3837,9 @@ g_key_file_add_group (GKeyFile *key_file,
if (key_file->start_group == NULL)
key_file->start_group = group;
+ if (!key_file->group_hash)
+ key_file->group_hash = g_hash_table_new (g_str_hash, g_str_equal);
+
g_hash_table_insert (key_file->group_hash, (gpointer)group->name, group);
}
@@ -4095,6 +4098,9 @@ static GKeyFileGroup *
g_key_file_lookup_group (GKeyFile *key_file,
const gchar *group_name)
{
+ if (!key_file->group_hash)
+ return NULL;
+
return (GKeyFileGroup *)g_hash_table_lookup (key_file->group_hash, group_name);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]