[gtksourceview] searchcontext: avoid use of GtkTextIter across main loop boundary



commit ca213ca11b46432dc144fbbacda9eb8ee75402dd
Author: Christian Hergert <chergert redhat com>
Date:   Sun Feb 17 15:47:44 2019 -0800

    searchcontext: avoid use of GtkTextIter across main loop boundary
    
    This avoids stashing a GtkTextIter which is not guaranteed to be safe
    across a return to the main loop as the text btree could be updated.
    
    There is a relatively insignificant performance impact shown by the
    test-search-performances test.
    
    Fixes #8

 gtksourceview/gtksourcesearchcontext.c | 48 ++++++++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 8 deletions(-)
---
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index 68415c3d..90811670 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -357,8 +357,8 @@ struct _GtkSourceSearchContextPrivate
 typedef struct
 {
        GtkTextMark *start_at;
-       GtkTextIter match_start;
-       GtkTextIter match_end;
+       GtkTextMark *match_start;
+       GtkTextMark *match_end;
        guint found : 1;
        guint wrapped_around : 1;
 
@@ -958,6 +958,18 @@ forward_backward_data_free (ForwardBackwardData *data)
                gtk_text_buffer_delete_mark (buffer, data->start_at);
        }
 
+       if (data->match_start != NULL)
+       {
+               GtkTextBuffer *buffer = gtk_text_mark_get_buffer (data->match_start);
+               gtk_text_buffer_delete_mark (buffer, data->match_start);
+       }
+
+       if (data->match_end != NULL)
+       {
+               GtkTextBuffer *buffer = gtk_text_mark_get_buffer (data->match_end);
+               gtk_text_buffer_delete_mark (buffer, data->match_end);
+       }
+
        g_slice_free (ForwardBackwardData, data);
 }
 
@@ -1035,8 +1047,16 @@ smart_forward_search_async_step (GtkSourceSearchContext *search,
 
                        task_data = g_slice_new0 (ForwardBackwardData);
                        task_data->found = TRUE;
-                       task_data->match_start = match_start;
-                       task_data->match_end = match_end;
+                       task_data->match_start =
+                                gtk_text_buffer_create_mark (search->priv->buffer,
+                                                             NULL,
+                                                             &match_start,
+                                                             TRUE);
+                       task_data->match_end =
+                                gtk_text_buffer_create_mark (search->priv->buffer,
+                                                             NULL,
+                                                             &match_end,
+                                                             FALSE);
                        task_data->is_forward = TRUE;
                        task_data->wrapped_around = *wrapped_around;
 
@@ -1166,8 +1186,16 @@ smart_backward_search_async_step (GtkSourceSearchContext *search,
 
                        task_data = g_slice_new0 (ForwardBackwardData);
                        task_data->found = TRUE;
-                       task_data->match_start = match_start;
-                       task_data->match_end = match_end;
+                       task_data->match_start =
+                               gtk_text_buffer_create_mark (search->priv->buffer,
+                                                            NULL,
+                                                            &match_start,
+                                                            TRUE);
+                       task_data->match_end =
+                               gtk_text_buffer_create_mark (search->priv->buffer,
+                                                            NULL,
+                                                            &match_end,
+                                                            FALSE);
                        task_data->is_forward = FALSE;
                        task_data->wrapped_around = *wrapped_around;
 
@@ -3344,12 +3372,16 @@ gtk_source_search_context_forward_finish (GtkSourceSearchContext  *search,
        {
                if (match_start != NULL)
                {
-                       *match_start = data->match_start;
+                        gtk_text_buffer_get_iter_at_mark (search->priv->buffer,
+                                                          match_start,
+                                                          data->match_start);
                }
 
                if (match_end != NULL)
                {
-                       *match_end = data->match_end;
+                        gtk_text_buffer_get_iter_at_mark (search->priv->buffer,
+                                                          match_end,
+                                                          data->match_end);
                }
        }
 


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