GNOME Bugzilla – Bug 707703
Navigate quickly through a set of GtkTextMarks
Last modified: 2013-09-26 17:06:19 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.
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%).
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?
Use GQuark?
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.
Pushed. Will be available for GtkSourceView 3.12.