[gnome-text-editor] bufferscheduler: remove buffer from callback



commit f5f515a0ba9e93d1ad48f314be8802d05c78b8d6
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jul 14 17:56:53 2021 -0700

    bufferscheduler: remove buffer from callback
    
    It introduces difficulties in lifecycle tracking, so just drop it.

 src/editor-buffer-scheduler.c          | 30 +++++++++---------------------
 src/editor-buffer-scheduler.h          | 11 ++++-------
 src/editor-text-buffer-spell-adapter.c | 10 +++-------
 3 files changed, 16 insertions(+), 35 deletions(-)
---
diff --git a/src/editor-buffer-scheduler.c b/src/editor-buffer-scheduler.c
index 4def0bb..6510cdb 100644
--- a/src/editor-buffer-scheduler.c
+++ b/src/editor-buffer-scheduler.c
@@ -48,7 +48,6 @@ typedef struct
 typedef struct
 {
   GList link;
-  GtkTextBuffer *buffer;
   EditorBufferCallback callback;
   gpointer user_data;
   GDestroyNotify notify;
@@ -70,25 +69,20 @@ editor_buffer_task_free (EditorBufferTask *task)
   if (task->notify != NULL)
     task->notify (task->user_data);
 
-  g_clear_object (&task->buffer);
-
   g_slice_free (EditorBufferTask, task);
 }
 
 static EditorBufferTask *
-editor_buffer_task_new (GtkTextBuffer        *buffer,
-                        EditorBufferCallback  callback,
+editor_buffer_task_new (EditorBufferCallback  callback,
                         gpointer              user_data,
                         GDestroyNotify        notify)
 {
   EditorBufferTask *task;
 
-  g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
   g_return_val_if_fail (callback != NULL, NULL);
 
   task = g_slice_new0 (EditorBufferTask);
   task->link.data = task;
-  task->buffer = g_object_ref (buffer);
   task->callback = callback;
   task->user_data = user_data;
   task->notify = notify;
@@ -158,12 +152,9 @@ editor_buffer_scheduler_dispatch (GSource     *source,
       if (task == NULL)
         break;
 
-      /* Liveliness check to catch miss-use early */
-      g_assert (GTK_IS_TEXT_BUFFER (task->buffer));
-
       g_queue_unlink (&self->queue, &task->link);
 
-      if (task->callback (task->buffer, deadline, task->user_data))
+      if (task->callback (deadline, task->user_data))
         {
           task->ready_time = current + interval;
           g_queue_push_tail_link (&self->queue, &task->link);
@@ -220,27 +211,24 @@ get_scheduler (void)
 }
 
 gsize
-editor_buffer_scheduler_add (GtkTextBuffer        *buffer,
-                             EditorBufferCallback  callback,
-                             gpointer              user_data)
+editor_buffer_scheduler_add (EditorBufferCallback callback,
+                             gpointer             user_data)
 {
-  return editor_buffer_scheduler_add_full (buffer, callback, user_data, NULL);
+  return editor_buffer_scheduler_add_full (callback, user_data, NULL);
 }
 
 gsize
-editor_buffer_scheduler_add_full (GtkTextBuffer        *buffer,
-                                  EditorBufferCallback  callback,
-                                  gpointer              user_data,
-                                  GDestroyNotify        notify)
+editor_buffer_scheduler_add_full (EditorBufferCallback callback,
+                                  gpointer             user_data,
+                                  GDestroyNotify       notify)
 {
   EditorBufferScheduler *self;
   EditorBufferTask *task;
 
-  g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), 0);
   g_return_val_if_fail (callback != NULL, 0);
 
   self = get_scheduler ();
-  task = editor_buffer_task_new (buffer, callback, user_data, notify);
+  task = editor_buffer_task_new (callback, user_data, notify);
   task->id = ++self->last_handler_id;
 
   /* Request progress immediately */
diff --git a/src/editor-buffer-scheduler.h b/src/editor-buffer-scheduler.h
index 212a0dd..172d9c1 100644
--- a/src/editor-buffer-scheduler.h
+++ b/src/editor-buffer-scheduler.h
@@ -24,15 +24,12 @@
 
 G_BEGIN_DECLS
 
-typedef gboolean (*EditorBufferCallback) (GtkTextBuffer *buffer,
-                                          gint64         deadline,
-                                          gpointer       user_data);
+typedef gboolean (*EditorBufferCallback) (gint64   deadline,
+                                          gpointer user_data);
 
-gsize editor_buffer_scheduler_add      (GtkTextBuffer        *buffer,
-                                        EditorBufferCallback  callback,
+gsize editor_buffer_scheduler_add      (EditorBufferCallback  callback,
                                         gpointer              user_data);
-gsize editor_buffer_scheduler_add_full (GtkTextBuffer        *buffer,
-                                        EditorBufferCallback  callback,
+gsize editor_buffer_scheduler_add_full (EditorBufferCallback  callback,
                                         gpointer              user_data,
                                         GDestroyNotify        notify);
 void  editor_buffer_scheduler_remove   (gsize                 handler_id);
diff --git a/src/editor-text-buffer-spell-adapter.c b/src/editor-text-buffer-spell-adapter.c
index becbc0b..60e73b7 100644
--- a/src/editor-text-buffer-spell-adapter.c
+++ b/src/editor-text-buffer-spell-adapter.c
@@ -195,9 +195,8 @@ editor_text_buffer_spell_adapter_update_range (EditorTextBufferSpellAdapter *sel
 }
 
 static gboolean
-editor_text_buffer_spell_adapter_run (GtkTextBuffer *buffer,
-                                      gint64         deadline,
-                                      gpointer       user_data)
+editor_text_buffer_spell_adapter_run (gint64   deadline,
+                                      gpointer user_data)
 {
   EditorTextBufferSpellAdapter *self = user_data;
 
@@ -224,10 +223,7 @@ editor_text_buffer_spell_adapter_queue_update (EditorTextBufferSpellAdapter *sel
     }
 
   if (self->update_source == 0)
-    editor_buffer_scheduler_add_full (self->buffer,
-                                      editor_text_buffer_spell_adapter_run,
-                                      g_object_ref (self),
-                                      g_object_unref);
+    editor_buffer_scheduler_add (editor_text_buffer_spell_adapter_run, self);
 }
 
 static void


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