[gtksourceview/gnome-3-24] searchcontext: avoid use of GtkTextIter across main loop boundary
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/gnome-3-24] searchcontext: avoid use of GtkTextIter across main loop boundary
- Date: Sun, 17 Feb 2019 23:50:29 +0000 (UTC)
commit c43dbdad4f9ebf25dca18573a2c95c73d0d108a8
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 37aa447c..b6a71596 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -360,8 +360,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;
@@ -961,6 +961,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);
}
@@ -1038,8 +1050,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;
@@ -1169,8 +1189,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;
@@ -3439,12 +3467,16 @@ gtk_source_search_context_forward_finish2 (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]