[gtksourceview] CompletionWords buffer: clarify idle_scan_regions()



commit d5b7ced10b8bf3748fd4f97fbcd76bf612b2444b
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat May 25 15:56:30 2013 +0200

    CompletionWords buffer: clarify idle_scan_regions()
    
    The code was correct (I think), but it was hard to understand. Now it is
    still correct (hopefully), but a little easier to understand.

 .../words/gtksourcecompletionwordsbuffer.c         |   29 +++++++++++--------
 1 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c 
b/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
index 04144b5..e946c07 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
@@ -340,10 +340,11 @@ idle_scan_regions (GtkSourceCompletionWordsBuffer *buffer)
        gboolean finished;
        guint num = buffer->priv->scan_batch_size;
 
-       /* Scan some regions */
-       while (buffer->priv->scan_regions)
+       /* Scan some regions (maximum 'num' lines) */
+       while (buffer->priv->scan_regions != NULL && num > 0)
        {
                ScanRegion *region = buffer->priv->scan_regions->data;
+               gboolean region_done = FALSE;
                GtkTextIter start;
                GtkTextIter end;
 
@@ -355,27 +356,32 @@ idle_scan_regions (GtkSourceCompletionWordsBuffer *buffer)
                                                  &end,
                                                  region->end);
 
-               while (gtk_text_iter_compare (&start, &end) < 0 && num)
+               while (TRUE)
                {
                        GSList *words;
 
+                       if (gtk_text_iter_compare (&start, &end) >= 0)
+                       {
+                               region_done = TRUE;
+                               break;
+                       }
+
+                       if (num == 0)
+                       {
+                               break;
+                       }
+
                        words = scan_line (buffer, &start);
 
                        /* add_words also frees the list */
                        add_words (buffer, words);
 
                        --num;
-
-                       if (!gtk_text_iter_forward_line (&start))
-                       {
-                               num = 0;
-                               break;
-                       }
+                       gtk_text_iter_forward_line (&start);
                }
 
-               if (gtk_text_iter_compare (&start, &end) >= 0 || num != 0)
+               if (region_done)
                {
-                       /* Done with region */
                        scan_region_free (region);
                        buffer->priv->scan_regions = g_list_delete_link (buffer->priv->scan_regions,
                                                                         buffer->priv->scan_regions);
@@ -385,7 +391,6 @@ idle_scan_regions (GtkSourceCompletionWordsBuffer *buffer)
                        gtk_text_buffer_move_mark (buffer->priv->buffer,
                                                   region->start,
                                                   &start);
-                       break;
                }
        }
 


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