[gtksourceview/wip/search: 23/36] search: speed up the search (almost 2x faster)
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/search: 23/36] search: speed up the search (almost 2x faster)
- Date: Sat, 6 Jul 2013 15:58:39 +0000 (UTC)
commit 9f3c9a21bdf4fe0f0ed5ae690e4d152010e3c4d5
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue Jul 2 19:38:48 2013 +0200
search: speed up the search (almost 2x faster)
It was a known performance issue, not difficult to fix.
gtksourceview/gtksourcesearch.c | 70 ++++++++++++++++++++++++++++++++-------
1 files changed, 58 insertions(+), 12 deletions(-)
---
diff --git a/gtksourceview/gtksourcesearch.c b/gtksourceview/gtksourcesearch.c
index 7160f97..4242e5b 100644
--- a/gtksourceview/gtksourcesearch.c
+++ b/gtksourceview/gtksourcesearch.c
@@ -829,6 +829,58 @@ adjust_subregion (GtkSourceSearch *search,
});
}
+/* Do not take into account the scan_region. Search just with
+ * forward_to_tag_toggle(), and checks that it is not an old match.
+ */
+static gboolean
+smart_forward_search_without_scanning (GtkSourceSearch *search,
+ const GtkTextIter *start_at,
+ GtkTextIter *match_start,
+ GtkTextIter *match_end,
+ const GtkTextIter *stop_at)
+{
+ GtkTextIter iter = *start_at;
+ GtkTextIter limit;
+
+ g_assert (start_at != NULL);
+ g_assert (stop_at != NULL);
+
+ if (gtk_text_iter_compare (stop_at, start_at) <= 0 ||
+ search->priv->text == NULL)
+ {
+ return FALSE;
+ }
+
+ if (search->priv->found_tag == NULL)
+ {
+ init_found_tag (search);
+ }
+
+ if (!gtk_text_iter_has_tag (&iter, search->priv->found_tag))
+ {
+ gtk_text_iter_forward_to_tag_toggle (&iter, search->priv->found_tag);
+ }
+
+ limit = iter;
+ gtk_text_iter_forward_to_tag_toggle (&limit, search->priv->found_tag);
+
+ if (gtk_text_iter_compare (stop_at, &limit) < 0)
+ {
+ limit = *stop_at;
+ }
+
+ if (basic_forward_search (search, &iter, match_start, match_end, &limit))
+ {
+ return TRUE;
+ }
+
+ return smart_forward_search_without_scanning (search,
+ &limit,
+ match_start,
+ match_end,
+ stop_at);
+}
+
/* Remove the occurrences in the range. @start and @end may be adjusted, if they
* are in a found_tag region.
*/
@@ -858,20 +910,9 @@ remove_occurrences_in_range (GtkSourceSearch *search,
gtk_text_iter_forward_to_tag_toggle (end, search->priv->found_tag);
}
- gtk_text_buffer_remove_tag (search->priv->buffer,
- search->priv->found_tag,
- start,
- end);
-
- if (search->priv->text == NULL)
- {
- return;
- }
-
iter = *start;
- /* TODO optimization: search with forward_to_tag_toggle() */
- while (basic_forward_search (search, &iter, &match_start, &match_end, end))
+ while (smart_forward_search_without_scanning (search, &iter, &match_start, &match_end, end))
{
if (search->priv->scan_region == NULL)
{
@@ -898,6 +939,11 @@ remove_occurrences_in_range (GtkSourceSearch *search,
iter = match_end;
}
+
+ gtk_text_buffer_remove_tag (search->priv->buffer,
+ search->priv->found_tag,
+ start,
+ end);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]