[gtksourceview] sourceview: avoid inspecting GtkTextIter that are not spaces



commit 64d869a6247611ab52f48c4a7792ec4d119e8fa7
Author: Christian Hergert <christian hergert me>
Date:   Tue Apr 19 05:56:58 2016 -0700

    sourceview: avoid inspecting GtkTextIter that are not spaces
    
    This avoids calling space_needs_drawing() for characters that are not
    spaces.
    
    This cuts about 7% out of cumulative time in draw_tabs_and_spaces(), by
    reducing how much we call space_needs_drawing(). That callchain is
    expensive and should be avoided (or changed).
    
    Before
          SELF CUMULATIVE    FUNCTION
    [   0.00%] [  23.53%]    gtk_source_view_draw_layer
    [   0.02%] [  19.32%]      draw_tabs_and_spaces
    [   0.04%] [   6.70%]        space_needs_drawing
    [   0.00%] [   5.56%]        gtk_text_view_get_iter_at_location
    [   0.02%] [   2.34%]        draw_spaces_at_iter
    [   0.01%] [   1.58%]        gtk_text_iter_forward_char
    [   0.01%] [   1.09%]        get_leading_trailing
    [   0.00%] [   0.93%]        get_end_iter
    
    
    After
          SELF CUMULATIVE    FUNCTION
    [   0.00%] [  16.17%]    gtk_source_view_draw_layer
    [   0.02%] [  12.20%]      draw_tabs_and_spaces
    [   0.00%] [   4.41%]        gtk_text_view_get_iter_at_location
    [   0.02%] [   2.03%]        draw_spaces_at_iter
    [   0.01%] [   1.41%]        space_needs_drawing
    [   0.01%] [   1.29%]        gtk_text_iter_forward_char
    [   0.01%] [   0.84%]        get_leading_trailing
    [   0.00%] [   0.71%]        get_end_iter

 gtksourceview/gtksourceview.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 2e716f1..3093654 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -2695,6 +2695,14 @@ get_end_iter (GtkTextView *text_view,
        }
 }
 
+static inline gboolean
+is_space (gunichar c)
+{
+       return (g_unichar_isspace (c) ||
+               (g_unichar_break_type (c) == G_UNICODE_BREAK_NON_BREAKING_GLUE) ||
+               (g_unichar_type (c) == G_UNICODE_SPACE_SEPARATOR));
+}
+
 static void
 draw_tabs_and_spaces (GtkSourceView *view,
                      cairo_t       *cr)
@@ -2747,8 +2755,10 @@ draw_tabs_and_spaces (GtkSourceView *view,
 
        while (TRUE)
        {
+               gunichar c = gtk_text_iter_get_char (&s);
                gint ly;
-               if (space_needs_drawing (view, &s, &leading, &trailing))
+
+               if (is_space (c) && space_needs_drawing (view, &s, &leading, &trailing))
                {
                        draw_spaces_at_iter (cr, text_view, &s);
                }


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