From de978d42317423ceb3041d773913473d564a0ec4 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 11 Jan 2013 13:00:56 -0500 Subject: Use g_hash_table_add() when using a hash table as a set. g_hash_table_add(table, key) uses less memory than g_hash_table_insert(table, key, GINT_TO_POINTER (1)). Also use g_hash_table_contains() when testing for membership. --- mail/em-composer-utils.c | 10 ++++------ mail/em-subscription-editor.c | 11 ++++------- mail/em-vfolder-editor-rule.c | 19 +++++++++++++------ 3 files changed, 21 insertions(+), 19 deletions(-) (limited to 'mail') diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c index f75b83826a..204188f4e4 100644 --- a/mail/em-composer-utils.c +++ b/mail/em-composer-utils.c @@ -2405,9 +2405,9 @@ concat_unique_addrs (CamelInternetAddress *dest, gint i; for (i = 0; camel_internet_address_get (src, i, &name, &addr); i++) { - if (!g_hash_table_lookup (rcpt_hash, addr)) { + if (!g_hash_table_contains (rcpt_hash, addr)) { camel_internet_address_add (dest, name, addr); - g_hash_table_insert (rcpt_hash, (gchar *) addr, GINT_TO_POINTER (1)); + g_hash_table_add (rcpt_hash, (gpointer) addr); } } } @@ -2542,15 +2542,13 @@ em_utils_get_reply_all (ESourceRegistry *registry, while (camel_internet_address_get (reply_to, ii++, &name, &addr)) { /* Ignore references to the Reply-To address * in the To and Cc lists. */ - if (addr && !g_hash_table_lookup (rcpt_hash, addr)) { + if (addr && !g_hash_table_contains (rcpt_hash, addr)) { /* In the case we are doing a Reply-To-All, * we do not want to include the user's email * address because replying to oneself is * kinda silly. */ camel_internet_address_add (to, name, addr); - g_hash_table_insert ( - rcpt_hash, (gchar *) addr, - GINT_TO_POINTER (1)); + g_hash_table_add (rcpt_hash, (gpointer) addr); } } } diff --git a/mail/em-subscription-editor.c b/mail/em-subscription-editor.c index 5a372b9117..69e1271e5f 100644 --- a/mail/em-subscription-editor.c +++ b/mail/em-subscription-editor.c @@ -709,9 +709,9 @@ pick_all_cb (GtkTreeModel *model, if (can_pick_folder_info (tree_row_data->folder_info, data->mode) && (data->skip_folder_infos == NULL || - !g_hash_table_lookup_extended ( - data->skip_folder_infos, - tree_row_data->folder_info, NULL, NULL))) { + !g_hash_table_contains ( + data->skip_folder_infos, + tree_row_data->folder_info))) { g_queue_push_tail (data->out_tree_rows, tree_row_data); } else tree_row_data_free (tree_row_data); @@ -912,10 +912,7 @@ subscription_editor_unsubscribe_hidden (EMSubscriptionEditor *editor) if (tree_row_data == NULL) continue; - g_hash_table_insert ( - skip_shown, - tree_row_data->folder_info, - GINT_TO_POINTER (1)); + g_hash_table_add (skip_shown, tree_row_data->folder_info); tree_row_data_free (tree_row_data); } diff --git a/mail/em-vfolder-editor-rule.c b/mail/em-vfolder-editor-rule.c index 59c3713ed4..1319bdcee0 100644 --- a/mail/em-vfolder-editor-rule.c +++ b/mail/em-vfolder-editor-rule.c @@ -322,7 +322,11 @@ vfr_folder_response (EMFolderSelector *selector, selection = gtk_tree_view_get_selection (data->tree_view); gtk_tree_selection_unselect_all (selection); - known_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + known_uris = g_hash_table_new_full ( + (GHashFunc) g_str_hash, + (GEqualFunc) g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) NULL); if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (data->model), &iter)) { GtkTreeModel *model = GTK_TREE_MODEL (data->model); @@ -332,7 +336,7 @@ vfr_folder_response (EMFolderSelector *selector, gtk_tree_model_get (model, &iter, 1, &known, -1); if (known) - g_hash_table_insert (known_uris, known, GINT_TO_POINTER (1)); + g_hash_table_add (known_uris, known); } while (gtk_tree_model_iter_next (model, &iter)); } @@ -340,10 +344,13 @@ vfr_folder_response (EMFolderSelector *selector, const gchar *uri = uris_iter->data; gchar *markup; - if (!uri || g_hash_table_lookup (known_uris, uri)) + if (uri == NULL) continue; - g_hash_table_insert (known_uris, g_strdup (uri), GINT_TO_POINTER (1)); + if (g_hash_table_contains (known_uris, uri)) + continue; + + g_hash_table_add (known_uris, g_strdup (uri)); changed = TRUE; g_queue_push_tail (em_vfolder_rule_get_sources (data->vr), g_strdup (uri)); @@ -425,7 +432,7 @@ source_remove (GtkWidget *widget, gtk_tree_path_append_index (path, index); if (gtk_tree_selection_path_is_selected (selection, path)) { - g_hash_table_insert (to_remove, GINT_TO_POINTER (index), GINT_TO_POINTER (1)); + g_hash_table_add (to_remove, GINT_TO_POINTER (index)); if (first_selected == -1) first_selected = index; @@ -444,7 +451,7 @@ source_remove (GtkWidget *widget, removed = 0; prev_source = NULL; while ((source = em_vfolder_rule_next_source (data->vr, source))) { - if (g_hash_table_lookup (to_remove, GINT_TO_POINTER (index + removed))) { + if (g_hash_table_contains (to_remove, GINT_TO_POINTER (index + removed))) { path = gtk_tree_path_new (); gtk_tree_path_append_index (path, index); gtk_tree_model_get_iter ( -- cgit v1.2.3