[gtk+] textiter: small optimization for find_by_log_attrs()



commit 472fd9a75fcaa445e2a7edd63a0d2d412c190417
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Apr 11 13:41:50 2014 +0200

    textiter: small optimization for find_by_log_attrs()
    
    Use gtk_text_iter_set_line_offset (&tmp_iter, 0) instead of
    gtk_text_iter_get_line(). The difference should not be big. In the first
    case the line doesn't need to be traversed thanks to the offset 0. For
    get_line(), the btree must be traversed.
    
    A temporary iter is needed to not break the behavior. But the behavior
    is quite strange, the function works directly on the iter passed as an
    argument to the function, even if the function returns FALSE (not
    found). So maybe a later commit will fix this strange behavior.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=629129

 gtk/gtktextiter.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtktextiter.c b/gtk/gtktextiter.c
index a97dea4..f445240 100644
--- a/gtk/gtktextiter.c
+++ b/gtk/gtktextiter.c
@@ -3131,14 +3131,18 @@ find_by_log_attrs (GtkTextIter     *iter,
         }
       else
         {
-          /* TODO optimize this part */
-          /* go to end of previous line. need to check that
-           * line is > 0 because backward_line snaps to start of
-           * line 0 if it's on line 0
+          GtkTextIter tmp_iter = *iter;
+
+          /* Go to end of previous line. First go to the current line offset 0,
+           * because backward_line() snaps to start of line 0 if iter is already
+           * on line 0.
            */
-          if (gtk_text_iter_get_line (iter) > 0 &&
-              gtk_text_iter_backward_line (iter))
+          gtk_text_iter_set_line_offset (&tmp_iter, 0);
+
+          if (gtk_text_iter_backward_line (&tmp_iter))
             {
+              *iter = tmp_iter;
+
               if (!gtk_text_iter_ends_line (iter))
                 gtk_text_iter_forward_to_line_end (iter);
 


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