[evolution-data-server] ESource: Use a collation key for display name comparisons.



commit 6af96e26e7f36f6f8390d3f3f239157ab742c822
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Jun 23 20:26:10 2012 -0400

    ESource: Use a collation key for display name comparisons.
    
    e_source_compare_by_display_name() gets called a lot.  We've been
    calling g_utf8_collate() each time, which is known to be slow when
    comparing large numbers of UTF-8 strings.
    
    We now stash a collation key during e_source_set_display_name()
    by passing the UTF-8 display name to g_utf8_collate_key().  Then
    in e_source_compare_by_display_name() we can simply call strcmp()
    on the internal collation keys to compare display names.
    
    Didn't take any real performance measurements other than seeing
    e_source_compare_by_display_name() topping the charts in sysprof.

 libedataserver/e-source.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/libedataserver/e-source.c b/libedataserver/e-source.c
index a913c7e..8a50e9e 100644
--- a/libedataserver/e-source.c
+++ b/libedataserver/e-source.c
@@ -116,7 +116,9 @@ struct _ESourcePrivate {
 	GMutex *changed_lock;
 
 	GMutex *property_lock;
+
 	gchar *display_name;
+	gchar *collate_key;
 	gchar *parent;
 	gchar *uid;
 
@@ -839,6 +841,7 @@ source_finalize (GObject *object)
 	g_mutex_free (priv->property_lock);
 
 	g_free (priv->display_name);
+	g_free (priv->collate_key);
 	g_free (priv->parent);
 	g_free (priv->uid);
 
@@ -1892,6 +1895,10 @@ e_source_set_display_name (ESource *source,
 	/* Strip leading and trailing whitespace. */
 	g_strstrip (source->priv->display_name);
 
+	/* This is used in e_source_compare_by_display_name(). */
+	g_free (source->priv->collate_key);
+	source->priv->collate_key = g_utf8_collate_key (display_name, -1);
+
 	g_mutex_unlock (source->priv->property_lock);
 
 	g_object_notify (G_OBJECT (source), "display-name");
@@ -1915,13 +1922,9 @@ gint
 e_source_compare_by_display_name (ESource *source1,
                                   ESource *source2)
 {
-	const gchar *display_name1;
-	const gchar *display_name2;
-
-	display_name1 = e_source_get_display_name (source1);
-	display_name2 = e_source_get_display_name (source2);
-
-	return g_utf8_collate (display_name1, display_name2);
+	return g_strcmp0 (
+		source1->priv->collate_key,
+		source2->priv->collate_key);
 }
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]