[gtksourceview/gnome-3-20] gutter: avoid gtk_text_iter_forward_to_line_end() when possible



commit bb2a9233a692587e5a5fe77a7c691d8b2897b136
Author: Christian Hergert <chergert redhat com>
Date:   Wed Apr 20 01:49:10 2016 -0700

    gutter: avoid gtk_text_iter_forward_to_line_end() when possible
    
    When calculating line heights for gutter cells, we don't need precise
    access to the beginning of the newline breaks. forward_to_line_end()
    will place us just before the \r\n, \n, etc. Instead, we can cheat and
    use the line index to jump to the next line and then backwards a char.
    
    This is clearly a micro optimization (about 1-2% on my tests), but as
    the line numbers are roughly 2x the cost of the text window, we just
    need a few more of these here and there.

 gtksourceview/gtksourcegutter.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutter.c b/gtksourceview/gtksourcegutter.c
index e21e1a3..2e00b86 100644
--- a/gtksourceview/gtksourcegutter.c
+++ b/gtksourceview/gtksourcegutter.c
@@ -1092,7 +1092,18 @@ draw_cells (GtkSourceGutter *gutter,
 
                if (!gtk_text_iter_ends_line (&end))
                {
-                       gtk_text_iter_forward_to_line_end (&end);
+                       /*
+                        * It turns out that gtk_text_iter_forward_to_line_end
+                        * is slower than jumping to the next line in the
+                        * btree index and then moving backwards a character.
+                        * We don't really care that we might be after the
+                        * newline breaking characters, since those are part
+                        * of the same line (rather than the next line).
+                        */
+                       if (gtk_text_iter_forward_line (&end))
+                       {
+                               gtk_text_iter_backward_char (&end);
+                       }
                }
 
                /* Possible improvement: if buffer and window coords have the


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