Bug 707703 - Navigate quickly through a set of GtkTextMarks
Navigate quickly through a set of GtkTextMarks
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: General
unspecified
Other All
: Normal enhancement
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2013-09-07 22:25 UTC by Sébastien Wilmet
Modified: 2013-09-26 17:06 UTC (History)
2 users (show)

See Also:
GNOME target: ---
GNOME version: ---


Attachments
Implement private class GtkSourceMarksSequence (46.10 KB, patch)
2013-09-09 21:10 UTC, Sébastien Wilmet
none Details | Diff | Review

Description Sébastien Wilmet 2013-09-07 22:25:11 UTC
GtkSourceBuffer uses a GArray for storing GtkSourceMarks. This is not a problem if there are only a few marks. But as the number of marks increases, this becomes a problem.

There is a similar issue for implementing the code folding. Folds in a buffer is like a tree. There can be folds inside other folds. But no overlapping. The problem is that the branching factor can be large. For example a document with hundreds of sections. Given a GtkTextIter, we have to find quickly the corresponding folds, to draw them in the gutter.

So to simplify the code folding, and to improve GtkSourceMarks, we can write a utility class around GtkTextMarks, called e.g. GtkSourceMarkSequence.

We create a GtkSourceMarkSequence object, and we store text marks in it. The text marks are sorted. We can navigate through them quickly. There would be a function to find the nearest text mark before or after a certain text iter, etc.

Internally, the MarkSequence can use a GSequence.
Comment 1 Sébastien Wilmet 2013-09-09 21:10:54 UTC
Created attachment 254521 [details] [review]
Implement private class GtkSourceMarksSequence

And use it for GtkSourceMarks. It will be useful for the code folding
too.

The unit tests are in the yellow (>= 75%).
Comment 2 Sébastien Wilmet 2013-09-09 21:12:59 UTC
Review of attachment 254521 [details] [review]:

::: gtksourceview/gtksourcemarkssequence.c
@@ +242,3 @@
+
+	unique_str = g_strdup_printf ("gtk-source-marks-sequence-%p", seq);
+	seq->priv->quark = g_quark_from_string (unique_str);

Is there a recommended way to generate a unique quark?
Comment 3 Ignacio Casal Quinteiro (nacho) 2013-09-10 06:08:49 UTC
Use GQuark?
Comment 4 Sébastien Wilmet 2013-09-10 11:37:31 UTC
The quark must be different for each MarksSequence instance. It is used to store the GSequenceIter in the GtkTextMark with g_object_set_qdata(). A GtkTextMark can be present in several MarksSequence instances, so the quark must be different for each instance.
Comment 5 Sébastien Wilmet 2013-09-26 17:06:19 UTC
Pushed. Will be available for GtkSourceView 3.12.

Note You need to log in before you can comment on or make changes to this bug.