mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
Speed up group lookups
svn path=/trunk/; revision=6018
This commit is contained in:
parent
7561ec5765
commit
8e2e557633
@ -1,3 +1,8 @@
|
||||
2007-12-03 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* glib/gkeyfile.c: Add a hash table to speed up group lookups,
|
||||
which GKeyFile does quite a lot.
|
||||
|
||||
2007-12-03 Alexander Larsson <alexl@redhat.com>
|
||||
|
||||
* configure.in:
|
||||
|
@ -67,6 +67,7 @@ typedef struct _GKeyFileGroup GKeyFileGroup;
|
||||
struct _GKeyFile
|
||||
{
|
||||
GList *groups;
|
||||
GHashTable *group_hash;
|
||||
|
||||
GKeyFileGroup *start_group;
|
||||
GKeyFileGroup *current_group;
|
||||
@ -199,6 +200,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->start_group = NULL;
|
||||
key_file->parse_buffer = g_string_sized_new (128);
|
||||
key_file->approximate_size = 0;
|
||||
@ -2802,8 +2804,8 @@ g_key_file_get_group_comment (GKeyFile *key_file,
|
||||
GList *group_node;
|
||||
GKeyFileGroup *group;
|
||||
|
||||
group_node = g_key_file_lookup_group_node (key_file, group_name);
|
||||
if (!group_node)
|
||||
group = g_key_file_lookup_group (key_file, group_name);
|
||||
if (!group)
|
||||
{
|
||||
g_set_error (error, G_KEY_FILE_ERROR,
|
||||
G_KEY_FILE_ERROR_GROUP_NOT_FOUND,
|
||||
@ -2813,10 +2815,10 @@ g_key_file_get_group_comment (GKeyFile *key_file,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
group = (GKeyFileGroup *)group_node->data;
|
||||
if (group->comment)
|
||||
return g_strdup (group->comment->value);
|
||||
|
||||
group_node = g_key_file_lookup_group_node (key_file, group_name);
|
||||
group_node = group_node->next;
|
||||
group = (GKeyFileGroup *)group_node->data;
|
||||
return get_group_comment (key_file, group, error);
|
||||
@ -2923,7 +2925,7 @@ g_key_file_has_group (GKeyFile *key_file,
|
||||
g_return_val_if_fail (key_file != NULL, FALSE);
|
||||
g_return_val_if_fail (group_name != NULL, FALSE);
|
||||
|
||||
return g_key_file_lookup_group_node (key_file, group_name) != NULL;
|
||||
return g_key_file_lookup_group (key_file, group_name) != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2996,6 +2998,8 @@ 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);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -3050,6 +3054,9 @@ g_key_file_remove_group_node (GKeyFile *key_file,
|
||||
|
||||
group = (GKeyFileGroup *) group_node->data;
|
||||
|
||||
if (group->name)
|
||||
g_hash_table_remove (key_file->group_hash, group->name);
|
||||
|
||||
/* If the current group gets deleted make the current group the last
|
||||
* added group.
|
||||
*/
|
||||
@ -3250,14 +3257,7 @@ static GKeyFileGroup *
|
||||
g_key_file_lookup_group (GKeyFile *key_file,
|
||||
const gchar *group_name)
|
||||
{
|
||||
GList *group_node;
|
||||
|
||||
group_node = g_key_file_lookup_group_node (key_file, group_name);
|
||||
|
||||
if (group_node != NULL)
|
||||
return (GKeyFileGroup *) group_node->data;
|
||||
|
||||
return NULL;
|
||||
return (GKeyFileGroup *)g_hash_table_lookup (key_file->group_hash, group_name);
|
||||
}
|
||||
|
||||
static GList *
|
||||
|
Loading…
Reference in New Issue
Block a user