[dconf] Optimise is_writable() for the common case



commit 81ac70655d1f41cf9db63c94387e04cf6a5cbf65
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri May 6 14:46:07 2011 +0200

    Optimise is_writable() for the common case
    
    ...of no system defaults database.

 engine/dconf-engine.c |   31 +++++++++++++++++--------------
 1 files changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/engine/dconf-engine.c b/engine/dconf-engine.c
index 9e7d4b2..ec99116 100644
--- a/engine/dconf-engine.c
+++ b/engine/dconf-engine.c
@@ -536,24 +536,27 @@ dconf_engine_is_writable (DConfEngine *engine,
                           const gchar *name)
 {
   gboolean writable = TRUE;
-  gint i;
 
-  g_static_mutex_lock (&engine->lock);
+  /* Only check if we have at least one system database */
+  if (engine->n_dbs > 1)
+    {
+      gint i;
 
-  dconf_engine_refresh (engine);
+      g_static_mutex_lock (&engine->lock);
 
-  /* Don't check for locks in the user database.
-   * If there is only a user database then the loop won't run at all.
-   */
-  for (i = engine->n_dbs - 1; 0 < i; i--)
-    if (engine->lock_tables[i] != NULL &&
-        gvdb_table_has_value (engine->lock_tables[i], name))
-      {
-        writable = FALSE;
-        break;
-      }
+      dconf_engine_refresh_system (engine);
 
-  g_static_mutex_unlock (&engine->lock);
+      /* Don't check for locks in the user database (i == 0). */
+      for (i = engine->n_dbs - 1; 0 < i; i--)
+        if (engine->lock_tables[i] != NULL &&
+            gvdb_table_has_value (engine->lock_tables[i], name))
+          {
+            writable = FALSE;
+            break;
+          }
+
+      g_static_mutex_unlock (&engine->lock);
+    }
 
   return writable;
 }



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