[evolution] Use g_hash_table_add() when using a hash table as a set.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Use g_hash_table_add() when using a hash table as a set.
- Date: Fri, 11 Jan 2013 18:44:09 +0000 (UTC)
commit de978d42317423ceb3041d773913473d564a0ec4
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Jan 11 13:00:56 2013 -0500
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.
composer/e-msg-composer.c | 15 +++++++--------
e-util/e-table-field-chooser-item.c | 18 +++++++++++-------
libemail-engine/e-mail-utils.c | 10 +++-------
libemail-engine/em-vfolder-rule.c | 21 ++++++++++++++++-----
mail/em-composer-utils.c | 10 ++++------
mail/em-subscription-editor.c | 11 ++++-------
mail/em-vfolder-editor-rule.c | 19 +++++++++++++------
7 files changed, 58 insertions(+), 46 deletions(-)
---
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 82f1b30..8d0252c 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -3041,10 +3041,7 @@ composer_add_auto_recipients (ESource *source,
const gchar *addr;
if (camel_internet_address_get (inet_addr, ii, &name, &addr))
- g_hash_table_insert (
- hash_table,
- g_strdup (addr),
- GINT_TO_POINTER (1));
+ g_hash_table_add (hash_table, g_strdup (addr));
}
g_object_unref (inet_addr);
@@ -3127,12 +3124,14 @@ e_msg_composer_new_with_message (EShell *shell,
if (postto == NULL) {
auto_cc = g_hash_table_new_full (
- camel_strcase_hash, camel_strcase_equal,
+ (GHashFunc) camel_strcase_hash,
+ (GEqualFunc) camel_strcase_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) NULL);
auto_bcc = g_hash_table_new_full (
- camel_strcase_hash, camel_strcase_equal,
+ (GHashFunc) camel_strcase_hash,
+ (GEqualFunc) camel_strcase_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) NULL);
@@ -3169,7 +3168,7 @@ e_msg_composer_new_with_message (EShell *shell,
e_destination_set_name (dest, name);
e_destination_set_email (dest, addr);
- if (g_hash_table_lookup (auto_cc, addr))
+ if (g_hash_table_contains (auto_cc, addr))
e_destination_set_auto_recipient (dest, TRUE);
Cc = g_list_append (Cc, dest);
@@ -3189,7 +3188,7 @@ e_msg_composer_new_with_message (EShell *shell,
e_destination_set_name (dest, name);
e_destination_set_email (dest, addr);
- if (g_hash_table_lookup (auto_bcc, addr))
+ if (g_hash_table_contains (auto_bcc, addr))
e_destination_set_auto_recipient (dest, TRUE);
Bcc = g_list_append (Bcc, dest);
diff --git a/e-util/e-table-field-chooser-item.c b/e-util/e-table-field-chooser-item.c
index f72e059..c7335f8 100644
--- a/e-util/e-table-field-chooser-item.c
+++ b/e-util/e-table-field-chooser-item.c
@@ -128,19 +128,23 @@ etfci_rebuild_combined (ETableFieldChooserItem *etfci)
ETableCol *ecol = e_table_header_get_column (etfci->header, i);
if (ecol->disabled)
continue;
- g_hash_table_insert (
- hash, GINT_TO_POINTER (ecol->col_idx),
- GINT_TO_POINTER (1));
+ g_hash_table_add (hash, GINT_TO_POINTER (ecol->col_idx));
}
count = e_table_header_count (etfci->full_header);
for (i = 0; i < count; i++) {
- ETableCol *ecol = e_table_header_get_column (etfci->full_header, i);
+ ETableCol *ecol;
+ gpointer key;
+
+ ecol = e_table_header_get_column (etfci->full_header, i);
+ key = GINT_TO_POINTER (ecol->col_idx);
+
if (ecol->disabled)
continue;
- if (!(GPOINTER_TO_INT (g_hash_table_lookup (
- hash, GINT_TO_POINTER (ecol->col_idx)))))
- e_table_header_add_column (etfci->combined_header, ecol, -1);
+
+ if (!g_hash_table_contains (hash, key))
+ e_table_header_add_column (
+ etfci->combined_header, ecol, -1);
}
g_hash_table_destroy (hash);
diff --git a/libemail-engine/e-mail-utils.c b/libemail-engine/e-mail-utils.c
index 30eee62..750e8cc 100644
--- a/libemail-engine/e-mail-utils.c
+++ b/libemail-engine/e-mail-utils.c
@@ -1104,7 +1104,7 @@ mail_account_in_recipients (ESourceRegistry *registry,
g_object_unref (source);
if (address != NULL) {
- match = (g_hash_table_lookup (recipients, address) != NULL);
+ match = g_hash_table_contains (recipients, address);
g_free (address);
}
@@ -1141,9 +1141,7 @@ em_utils_guess_mail_account_with_recipients (ESourceRegistry *registry,
gint index = 0;
while (camel_internet_address_get (addr, index++, NULL, &key))
- g_hash_table_insert (
- recipients, (gpointer) key,
- GINT_TO_POINTER (1));
+ g_hash_table_add (recipients, (gpointer) key);
}
type = CAMEL_RECIPIENT_TYPE_CC;
@@ -1152,9 +1150,7 @@ em_utils_guess_mail_account_with_recipients (ESourceRegistry *registry,
gint index = 0;
while (camel_internet_address_get (addr, index++, NULL, &key))
- g_hash_table_insert (
- recipients, (gpointer) key,
- GINT_TO_POINTER (1));
+ g_hash_table_add (recipients, (gpointer) key);
}
/* First Preference: We were given a folder that maps to an
diff --git a/libemail-engine/em-vfolder-rule.c b/libemail-engine/em-vfolder-rule.c
index 0d6b07a..ec6fdca 100644
--- a/libemail-engine/em-vfolder-rule.c
+++ b/libemail-engine/em-vfolder-rule.c
@@ -113,7 +113,9 @@ em_vfolder_rule_init (EMVFolderRule *rule)
rule->priv->autoupdate = TRUE;
/* it's using pointers from priv::sources, and those
* included has include_subfolders set to true */
- rule->priv->include_subfolders = g_hash_table_new (g_direct_hash, g_direct_equal);
+ rule->priv->include_subfolders = g_hash_table_new (
+ (GHashFunc) g_direct_hash,
+ (GEqualFunc) g_direct_equal);
rule->rule.source = g_strdup ("incoming");
}
@@ -214,7 +216,8 @@ em_vfolder_rule_sources_changed (EMVFolderRule *rule)
{
g_return_if_fail (rule != NULL);
- g_hash_table_foreach_remove (rule->priv->include_subfolders,
+ g_hash_table_foreach_remove (
+ rule->priv->include_subfolders,
check_queue_has_key, rule);
}
@@ -227,7 +230,11 @@ em_vfolder_rule_source_get_include_subfolders (EMVFolderRule *rule,
source = em_vfolder_rule_find_source (rule, source);
- return source && g_hash_table_lookup (rule->priv->include_subfolders, source);
+ if (source == NULL)
+ return FALSE;
+
+ return g_hash_table_contains (
+ rule->priv->include_subfolders, source);
}
void
@@ -242,9 +249,13 @@ em_vfolder_rule_source_set_include_subfolders (EMVFolderRule *rule,
g_return_if_fail (source != NULL);
if (include_subfolders)
- g_hash_table_insert (rule->priv->include_subfolders, (gpointer) source, GINT_TO_POINTER (1));
+ g_hash_table_add (
+ rule->priv->include_subfolders,
+ (gpointer) source);
else
- g_hash_table_remove (rule->priv->include_subfolders, (gpointer) source);
+ g_hash_table_remove (
+ rule->priv->include_subfolders,
+ (gpointer) source);
}
void
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index f75b838..204188f 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 5a372b9..69e1271 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 59c3713..1319bdc 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 (
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]