[gnome-builder] file-settings: cache IdeFileSettings after first load



commit f8365b41734ff61a489606e0f30ae5e11f9db1e8
Author: Christian Hergert <christian hergert me>
Date:   Wed May 6 15:11:15 2015 -0700

    file-settings: cache IdeFileSettings after first load
    
    Since we have an indirection object (IdeFileSettings), we don't need to
    worry about the single-bind-per-property allowance of GSettings.
    
    Therefore, we can aggressively cache these.

 libide/ide-file.c |   43 ++++++++++++++++++++++++++++++++++---------
 1 files changed, 34 insertions(+), 9 deletions(-)
---
diff --git a/libide/ide-file.c b/libide/ide-file.c
index 3a70b19..33ee045 100644
--- a/libide/ide-file.c
+++ b/libide/ide-file.c
@@ -30,14 +30,15 @@
 
 struct _IdeFile
 {
-  IdeObject      parent_instance;
-
-  gchar         *content_type;
-  GFile         *file;
-  IdeLanguage   *language;
-  gchar         *path;
-  GtkSourceFile *source_file;
-  guint          temporary_id;
+  IdeObject        parent_instance;
+
+  gchar           *content_type;
+  GFile           *file;
+  IdeFileSettings *file_settings;
+  IdeLanguage     *language;
+  gchar           *path;
+  GtkSourceFile   *source_file;
+  guint            temporary_id;
 };
 
 enum {
@@ -285,16 +286,22 @@ ide_file__file_settings_settled_cb (IdeFileSettings *file_settings,
                                     GParamSpec      *pspec,
                                     GTask           *task)
 {
+  IdeFile *self;
+
   IDE_ENTRY;
 
   g_assert (IDE_IS_FILE_SETTINGS (file_settings));
   g_assert (G_IS_TASK (task));
+  self = g_task_get_source_object (task);
+  g_assert (IDE_IS_FILE (self));
 
   if (ide_file_settings_get_settled (file_settings))
     {
       g_signal_handlers_disconnect_by_func (file_settings,
                                             G_CALLBACK (ide_file__file_settings_settled_cb),
                                             task);
+      if (self->file_settings == NULL)
+        self->file_settings = g_object_ref (file_settings);
       g_task_return_pointer (task, file_settings, g_object_unref);
       g_object_unref (task);
       IDE_EXIT;
@@ -319,14 +326,31 @@ ide_file_load_settings_async (IdeFile              *self,
 
   task = g_task_new (self, cancellable, callback, user_data);
 
+  /* Use shared instance if available */
+  if (self->file_settings != NULL)
+    {
+      g_task_return_pointer (task, g_object_ref (self->file_settings), g_object_unref);
+      IDE_EXIT;
+    }
+
+  /* Create our new settings instance, races are okay */
   file_settings = ide_file_settings_new (self);
 
+  /* If this is settled immediately (not using editorconfig), then we can use this now
+   * and cache the result for later
+   */
   if (ide_file_settings_get_settled (file_settings))
     {
-      g_task_return_pointer (task, file_settings, g_object_unref);
+      self->file_settings = file_settings;
+      g_task_return_pointer (task, g_object_ref (file_settings), g_object_unref);
       IDE_EXIT;
     }
 
+  /*
+   * We need to wait until the settings have settled. editorconfig may need to
+   * background load a bunch of .editorconfig files off of disk/sshfs/etc to
+   * determine the settings.
+   */
   g_signal_connect (file_settings,
                     "notify::settled",
                     G_CALLBACK (ide_file__file_settings_settled_cb),
@@ -406,6 +430,7 @@ ide_file_finalize (GObject *object)
 
   IDE_ENTRY;
 
+  g_clear_object (&self->file_settings);
   g_clear_object (&self->file);
   g_clear_object (&self->source_file);
   g_clear_object (&self->language);


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