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



commit 96814b57a6ec77df2c9385d1d0992d93d9a2b3e2
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 89311bf..0fa7ae6 100644
--- a/gtksourceview/gtksourcegutter.c
+++ b/gtksourceview/gtksourcegutter.c
@@ -1088,7 +1088,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]