[evolution] Bug 738453 - Inefficient sort by subject in message list
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug 738453 - Inefficient sort by subject in message list
- Date: Wed, 15 Oct 2014 17:38:28 +0000 (UTC)
commit c0da2e669cf859694cbd99a5a133e8bf94efab39
Author: Milan Crha <mcrha redhat com>
Date: Wed Oct 15 19:37:27 2014 +0200
Bug 738453 - Inefficient sort by subject in message list
e-util/e-poolv.c | 41 +++++++++++++----------------------------
mail/em-composer-utils.c | 2 +-
mail/em-utils.c | 32 ++++++++++++++++++++------------
mail/em-utils.h | 3 ++-
mail/message-list.c | 32 ++++++++++++++++++++++++++++----
5 files changed, 64 insertions(+), 46 deletions(-)
---
diff --git a/e-util/e-poolv.c b/e-util/e-poolv.c
index 701e6c2..1207d08 100644
--- a/e-util/e-poolv.c
+++ b/e-util/e-poolv.c
@@ -26,14 +26,9 @@
struct _EPoolv {
guchar length;
- gchar *s[1];
+ const gchar *s[1];
};
-static GHashTable *poolv_pool;
-static CamelMemPool *poolv_mempool;
-
-G_LOCK_DEFINE_STATIC (poolv);
-
/**
* e_poolv_new:
* @size: The number of elements in the poolv, maximum of 254 elements.
@@ -57,17 +52,6 @@ e_poolv_new (guint size)
poolv = g_malloc0 (sizeof (*poolv) + (size - 1) * sizeof (gchar *));
poolv->length = size;
- G_LOCK (poolv);
-
- if (!poolv_pool)
- poolv_pool = g_hash_table_new (g_str_hash, g_str_equal);
-
- if (!poolv_mempool)
- poolv_mempool = camel_mempool_new (
- 32 * 1024, 512, CAMEL_MEMPOOL_ALIGN_BYTE);
-
- G_UNLOCK (poolv);
-
return poolv;
}
@@ -91,26 +75,21 @@ e_poolv_set (EPoolv *poolv,
gchar *str,
gint freeit)
{
+ const gchar *old_str;
+
g_return_val_if_fail (poolv != NULL, NULL);
g_return_val_if_fail (index >= 0 && index < poolv->length, NULL);
if (!str) {
+ camel_pstring_free (poolv->s[index]);
poolv->s[index] = NULL;
return poolv;
}
- G_LOCK (poolv);
+ old_str = poolv->s[index];
+ poolv->s[index] = (gchar *) camel_pstring_add (str, freeit);
- if ((poolv->s[index] = g_hash_table_lookup (poolv_pool, str)) != NULL) {
- } else {
- poolv->s[index] = camel_mempool_strdup (poolv_mempool, str);
- g_hash_table_insert (poolv_pool, poolv->s[index], poolv->s[index]);
- }
-
- G_UNLOCK (poolv);
-
- if (freeit)
- g_free (str);
+ camel_pstring_free (old_str);
return poolv;
}
@@ -147,7 +126,13 @@ e_poolv_get (EPoolv *poolv,
void
e_poolv_destroy (EPoolv *poolv)
{
+ gint ii;
+
g_return_if_fail (poolv != NULL);
+ for (ii = 0; ii < poolv->length; ii++) {
+ camel_pstring_free (poolv->s[ii]);
+ }
+
g_free (poolv);
}
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index df3e1bf..931d763 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -2147,7 +2147,7 @@ reply_get_composer (EShell *shell,
if ((subject = (gchar *) camel_mime_message_get_subject (message))) {
gboolean skip_len = -1;
- if (em_utils_is_re_in_subject (subject, &skip_len) && skip_len > 0)
+ if (em_utils_is_re_in_subject (subject, &skip_len, NULL) && skip_len > 0)
subject = subject + skip_len;
subject = g_strdup_printf ("Re: %s", subject);
diff --git a/mail/em-utils.c b/mail/em-utils.c
index f1f23d3..544a7d5 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -1451,10 +1451,10 @@ check_prefix (const gchar *subject,
gboolean
em_utils_is_re_in_subject (const gchar *subject,
- gint *skip_len)
+ gint *skip_len,
+ const gchar * const *use_prefixes_strv)
{
- GSettings *settings;
- gchar *prefixes, **prefixes_strv;
+ gchar **prefixes_strv;
gboolean res;
gint ii;
@@ -1469,18 +1469,25 @@ em_utils_is_re_in_subject (const gchar *subject,
if (check_prefix (subject, "Re", skip_len))
return TRUE;
- settings = g_settings_new ("org.gnome.evolution.mail");
- prefixes = g_settings_get_string (settings, "composer-localized-re");
- g_object_unref (settings);
+ if (use_prefixes_strv) {
+ prefixes_strv = (gchar **) use_prefixes_strv;
+ } else {
+ GSettings *settings;
+ gchar *prefixes;
- if (!prefixes || !*prefixes) {
+ settings = g_settings_new ("org.gnome.evolution.mail");
+ prefixes = g_settings_get_string (settings, "composer-localized-re");
+ g_object_unref (settings);
+
+ if (!prefixes || !*prefixes) {
+ g_free (prefixes);
+ return FALSE;
+ }
+
+ prefixes_strv = g_strsplit (prefixes, ",", -1);
g_free (prefixes);
- return FALSE;
}
- prefixes_strv = g_strsplit (prefixes, ",", -1);
- g_free (prefixes);
-
if (!prefixes_strv)
return FALSE;
@@ -1493,7 +1500,8 @@ em_utils_is_re_in_subject (const gchar *subject,
res = check_prefix (subject, prefix, skip_len);
}
- g_strfreev (prefixes_strv);
+ if (!use_prefixes_strv)
+ g_strfreev (prefixes_strv);
return res;
}
diff --git a/mail/em-utils.h b/mail/em-utils.h
index 907a91b..ccd4f71 100644
--- a/mail/em-utils.h
+++ b/mail/em-utils.h
@@ -77,7 +77,8 @@ gchar *em_utils_url_unescape_amp (const gchar *url);
void emu_restore_folder_tree_state (EMFolderTree *folder_tree);
gboolean em_utils_is_re_in_subject (const gchar *subject,
- gint *skip_len);
+ gint *skip_len,
+ const gchar * const *use_prefixes_strv);
G_END_DECLS
diff --git a/mail/message-list.c b/mail/message-list.c
index 995dac5..43a0750 100644
--- a/mail/message-list.c
+++ b/mail/message-list.c
@@ -116,6 +116,10 @@ struct _MessageListPrivate {
const gchar *newest_read_uid;
time_t oldest_unread_date;
const gchar *oldest_unread_uid;
+
+ GSettings *mail_settings;
+ gchar **re_prefixes;
+ GMutex re_prefixes_lock;
};
/* XXX Plain GNode suffers from O(N) tail insertions, and that won't
@@ -776,8 +780,11 @@ get_normalised_string (MessageList *message_list,
subject = string;
while (found_re) {
+ g_mutex_lock (&message_list->priv->re_prefixes_lock);
found_re = em_utils_is_re_in_subject (
- subject, &skip_len) && skip_len > 0;
+ subject, &skip_len, (const gchar * const *) message_list->priv->re_prefixes)
&& skip_len > 0;
+ g_mutex_unlock (&message_list->priv->re_prefixes_lock);
+
if (found_re)
subject += skip_len;
@@ -1529,7 +1536,8 @@ add_all_labels_foreach (ETreeModel *etm,
}
static const gchar *
-get_trimmed_subject (CamelMessageInfo *info)
+get_trimmed_subject (CamelMessageInfo *info,
+ MessageList *message_list)
{
const gchar *subject;
const gchar *mlist;
@@ -1561,8 +1569,10 @@ get_trimmed_subject (CamelMessageInfo *info)
while (found_re) {
found_re = FALSE;
+ g_mutex_lock (&message_list->priv->re_prefixes_lock);
found_re = em_utils_is_re_in_subject (
- subject, &skip_len) && skip_len > 0;
+ subject, &skip_len, (const gchar * const *) message_list->priv->re_prefixes)
&& skip_len > 0;
+ g_mutex_unlock (&message_list->priv->re_prefixes_lock);
if (found_re)
subject += skip_len;
@@ -1677,7 +1687,7 @@ ml_tree_value_at_ex (ETreeModel *etm,
str = camel_message_info_subject (msg_info);
return (gpointer)(str ? str : "");
case COL_SUBJECT_TRIMMED:
- str = get_trimmed_subject (msg_info);
+ str = get_trimmed_subject (msg_info, message_list);
return (gpointer)(str ? str : "");
case COL_SUBJECT_NORM:
return (gpointer) get_normalised_string (message_list, msg_info, col);
@@ -2726,6 +2736,7 @@ message_list_dispose (GObject *object)
g_clear_object (&priv->session);
g_clear_object (&priv->folder);
g_clear_object (&priv->invisible);
+ g_clear_object (&priv->mail_settings);
g_clear_object (&message_list->extras);
@@ -2757,9 +2768,11 @@ message_list_finalize (GObject *object)
g_free (message_list->search);
g_free (message_list->frozen_search);
g_free (message_list->cursor_uid);
+ g_strfreev (message_list->priv->re_prefixes);
g_mutex_clear (&message_list->priv->regen_lock);
g_mutex_clear (&message_list->priv->thread_tree_lock);
+ g_mutex_clear (&message_list->priv->re_prefixes_lock);
clear_selection (message_list, &message_list->priv->clipboard);
@@ -3366,6 +3379,7 @@ message_list_init (MessageList *message_list)
g_mutex_init (&message_list->priv->regen_lock);
g_mutex_init (&message_list->priv->thread_tree_lock);
+ g_mutex_init (&message_list->priv->re_prefixes_lock);
/* TODO: Should this only get the selection if we're realised? */
p = message_list->priv;
@@ -3395,6 +3409,9 @@ message_list_init (MessageList *message_list)
/* FIXME This is currently unused. */
target_list = gtk_target_list_new (NULL, 0);
message_list->priv->paste_target_list = target_list;
+
+ message_list->priv->mail_settings = g_settings_new ("org.gnome.evolution.mail");
+ message_list->priv->re_prefixes = NULL;
}
static void
@@ -5866,6 +5883,7 @@ mail_regen_list (MessageList *message_list,
GCancellable *cancellable;
RegenData *new_regen_data;
RegenData *old_regen_data;
+ gchar *prefixes;
/* Report empty search as NULL, not as one/two-space string. */
if (search && (strcmp (search, " ") == 0 || strcmp (search, " ") == 0))
@@ -5878,6 +5896,12 @@ mail_regen_list (MessageList *message_list,
return;
}
+ g_mutex_lock (&message_list->priv->re_prefixes_lock);
+ g_strfreev (message_list->priv->re_prefixes);
+ prefixes = g_settings_get_string (message_list->priv->mail_settings, "composer-localized-re");
+ message_list->priv->re_prefixes = g_strsplit (prefixes ? prefixes : "", ",", -1);
+ g_mutex_unlock (&message_list->priv->re_prefixes_lock);
+
g_mutex_lock (&message_list->priv->regen_lock);
old_regen_data = message_list->priv->regen_data;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]