[glib/wip/schemasource: 12/24] GSettingsSchema: alter our 'reverse' technology



commit fd51edf0c4b6caeaa9358132a266a243b1c7604b
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Nov 15 07:16:48 2011 +0000

    GSettingsSchema: alter our 'reverse' technology
    
    Instead of building a reversed linked list by prepending in order and
    then reversing it at the end, prepend in reverse by iterating backwards
    through the directories (to get a list in-order when we're done).

 gio/gsettingsschema.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
index b79477c..47c4dc8 100644
--- a/gio/gsettingsschema.c
+++ b/gio/gsettingsschema.c
@@ -47,18 +47,25 @@ initialise_schema_sources (void)
 {
   static gsize initialised;
 
+  /* need a separate variable because 'schema_sources' may legitimately
+   * be null if we have zero valid schema sources
+   */
   if G_UNLIKELY (g_once_init_enter (&initialised))
     {
-      const gchar * const *dir;
+      const gchar * const *dirs;
       const gchar *path;
+      gint i;
 
-      for (dir = g_get_system_data_dirs (); *dir; dir++)
+      /* iterate in reverse: count up, then count down */
+      dirs = g_get_system_data_dirs ();
+      for (i = 0; dirs[i]; i++);
+
+      while (i--)
         {
           gchar *filename;
           GvdbTable *table;
 
-          filename = g_build_filename (*dir, "glib-2.0", "schemas",
-                                       "gschemas.compiled", NULL);
+          filename = g_build_filename (dirs[i], "glib-2.0", "schemas", "gschemas.compiled", NULL);
           table = gvdb_table_new (filename, TRUE, NULL);
 
           if (table != NULL)
@@ -67,8 +74,6 @@ initialise_schema_sources (void)
           g_free (filename);
         }
 
-      schema_sources = g_slist_reverse (schema_sources);
-
       if ((path = g_getenv ("GSETTINGS_SCHEMA_DIR")) != NULL)
         {
           gchar *filename;



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