[gtksourceview/gnome-3-24] SpaceDrawer: Avoid repeatedly checking last line



commit fe0049a36bd7f1e6a8ddb618dcafc2b659b0eda4
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Jul 22 08:54:33 2018 +1000

    SpaceDrawer: Avoid repeatedly checking last line
    
    The iteration logic for drawing spaces doesn't take into account the
    last line in the file, such that the last line always iterates across
    the entire length of the line, performing expensive GtkTextIter
    operations, even though it's already progressed past the end of the
    visible line. This causes problems on files with very long lines as the
    last line in the file, which is common on e.g., normal UTF-8 that's been
    incorrectly decoded as UTF-16.
    
    The fix here just checks to see whether the forward-to-next-line case
    actually forwards to a new line.

 gtksourceview/gtksourcespacedrawer.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/gtksourcespacedrawer.c b/gtksourceview/gtksourcespacedrawer.c
index 1c876f6e..25ece348 100644
--- a/gtksourceview/gtksourcespacedrawer.c
+++ b/gtksourceview/gtksourcespacedrawer.c
@@ -1433,7 +1433,13 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
                         */
                        if (!gtk_text_iter_starts_line (&next_iter))
                        {
-                               gtk_text_iter_forward_line (&next_iter);
+                               /* We're trying to move forward on the last
+                                * line of the buffer, so we can stop now.
+                                */
+                               if (!gtk_text_iter_forward_line (&next_iter))
+                               {
+                                       break;
+                               }
                        }
 
                        gtk_text_view_get_line_yrange (text_view, &next_iter, &ly, NULL);


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