[gnome-calendar/calendar-management] source-manager-dialog: reverse map sources to row
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/calendar-management] source-manager-dialog: reverse map sources to row
- Date: Fri, 30 Jan 2015 16:21:06 +0000 (UTC)
commit a6e17a2fa07ce4933e0ac8bc1a296520e096c6a7
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Jan 30 14:13:54 2015 -0200
source-manager-dialog: reverse map sources to row
This enable constant time lookup for rows.
src/gcal-source-manager-dialog.c | 24 +++++++-----------------
1 files changed, 7 insertions(+), 17 deletions(-)
---
diff --git a/src/gcal-source-manager-dialog.c b/src/gcal-source-manager-dialog.c
index 6dcc6f4..e2bd591 100644
--- a/src/gcal-source-manager-dialog.c
+++ b/src/gcal-source-manager-dialog.c
@@ -33,6 +33,7 @@ struct _GcalSourceManagerDialogPrivate
* Hash of GtkListBoxRow : ESource
*/
GHashTable *row_to_source;
+ GHashTable *source_to_row;
/* properties */
@@ -160,6 +161,7 @@ source_added_cb (GcalManager *manager,
row = make_row_for_source (GCAL_SOURCE_MANAGER_DIALOG (user_data), source);
g_hash_table_insert (priv->row_to_source, row, source);
+ g_hash_table_insert (priv->source_to_row, source, row);
gtk_container_add (GTK_CONTAINER (priv->sources_listbox), row);
}
@@ -178,26 +180,13 @@ source_removed_cb (GcalManager *manager,
gpointer user_data)
{
GcalSourceManagerDialogPrivate *priv;
- GList *keys, *aux;
+ GtkListBoxRow *row;
priv = gcal_source_manager_dialog_get_instance_private (GCAL_SOURCE_MANAGER_DIALOG (user_data));
- keys = g_hash_table_get_keys (priv->row_to_source);
+ row = g_hash_table_lookup (priv->source_to_row, source);
- for (aux = keys; aux != NULL; aux = aux->next)
- {
- ESource *current;
-
- current = g_hash_table_lookup (priv->row_to_source, aux->data);
-
- /* remove the entry */
- if (current == source)
- {
- g_hash_table_remove (priv->row_to_source, aux->data);
- break;
- }
- }
-
- g_list_free (keys);
+ g_hash_table_remove (priv->row_to_source, row);
+ g_hash_table_remove (priv->source_to_row, source);
}
/**
@@ -370,6 +359,7 @@ gcal_source_manager_dialog_init (GcalSourceManagerDialog *self)
priv->row_to_source = g_hash_table_new_full (g_direct_hash, g_direct_equal, (GDestroyNotify)
gtk_widget_destroy,
NULL);
+ priv->source_to_row = g_hash_table_new (g_direct_hash, g_direct_equal);
gtk_widget_init_template (GTK_WIDGET (self));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]