[gtksourceview] SpaceDrawer: Avoid repeatedly checking last line



commit 0d97d63d925dad35ddb5e376fb9160fde6be623b
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 52619e3f..62c87c4d 100644
--- a/gtksourceview/gtksourcespacedrawer.c
+++ b/gtksourceview/gtksourcespacedrawer.c
@@ -1283,7 +1283,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]