gparam performance



More performance patches from nautilus profiles.

Calling:
g_strcanon (pspec->name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-')

Is really inefficient, because it's gonna call strchr() on the large 
a-zA->Z0-9- string for every char in the key name. Since the char sets are 
ranges this can be done a lot better:

Index: gobject/gparam.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gparam.c,v
retrieving revision 1.21
diff -u -p -r1.21 gparam.c
--- gobject/gparam.c	19 Feb 2002 17:38:45 -0000	1.21
+++ gobject/gparam.c	10 Mar 2002 23:48:18 -0000
@@ -257,6 +257,21 @@ g_param_spec_get_blurb (GParamSpec *pspe
   return pspec->_blurb;
 }
 
+static void
+canonalize_key(gchar *key)
+{
+  gchar *p, c;
+
+  for (p = key; (c = *p) != 0; p++)
+    {
+      if (c != '-' &&
+	  (c < '0' || c > '9') &&
+	  (c < 'A' || c > 'Z') &&
+	  (c < 'a' || c > 'z'))
+	*p = '-';
+    }
+}
+
 gpointer
 g_param_spec_internal (GType        param_type,
 		       const gchar *name,
@@ -272,7 +287,7 @@ g_param_spec_internal (GType        para
 
   pspec = (gpointer) g_type_create_instance (param_type);
   pspec->name = g_strdup (name);
-  g_strcanon (pspec->name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
+  canonalize_key (pspec->name);
   pspec->_nick = g_strdup (nick);
   pspec->_blurb = g_strdup (blurb);
   pspec->flags = (flags & G_PARAM_USER_MASK) | (flags & G_PARAM_MASK);
@@ -650,7 +665,7 @@ param_spec_ht_lookup (GHashTable  *hash_
       key.name = g_strdup (param_name);
       key.owner_type = owner_type;
       
-      g_strcanon (key.name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
+      canonalize_key (key.name);
       if (walk_ancestors)
 	do
 	  {

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a benighted misogynist cyborg with no name. She's a brilliant cat-loving 
snake charmer from a family of eight older brothers. They fight crime! 




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