[gtksourceview: 5/5] region: remove get_subregion_count() and nth_subregion()



commit fb93e618b1016b8d1e3d06b50e14e8119dd78261
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Apr 2 13:01:55 2016 +0200

    region: remove get_subregion_count() and nth_subregion()
    
    Calling nth_subregion() in a loop is a bad idea since nth_subregion() is
    O(n). A GtkSourceRegionIter must be used instead.
    
    And knowing the number of subregions should not be necessary. It is in
    any case not used in GtkSourceView anymore.

 gtksourceview/gtksourceregion.c |   41 ---------------------------------------
 gtksourceview/gtksourceregion.h |    9 --------
 testsuite/test-region.c         |   18 +---------------
 3 files changed, 2 insertions(+), 66 deletions(-)
---
diff --git a/gtksourceview/gtksourceregion.c b/gtksourceview/gtksourceregion.c
index 77740bc..345e357 100644
--- a/gtksourceview/gtksourceregion.c
+++ b/gtksourceview/gtksourceregion.c
@@ -564,47 +564,6 @@ gtk_source_region_get_bounds (GtkSourceRegion *region,
        return TRUE;
 }
 
-guint
-gtk_source_region_get_subregion_count (GtkSourceRegion *region)
-{
-       g_return_val_if_fail (region != NULL, 0);
-
-       return g_list_length (region->subregions);
-}
-
-gboolean
-gtk_source_region_nth_subregion (GtkSourceRegion *region,
-                                guint            subregion,
-                                GtkTextIter     *start,
-                                GtkTextIter     *end)
-{
-       Subregion *sr;
-
-       g_return_val_if_fail (region != NULL, FALSE);
-
-       if (region->buffer == NULL)
-       {
-               return FALSE;
-       }
-
-       sr = g_list_nth_data (region->subregions, subregion);
-       if (sr == NULL)
-       {
-               return FALSE;
-       }
-
-       if (start != NULL)
-       {
-               gtk_text_buffer_get_iter_at_mark (region->buffer, start, sr->start);
-       }
-       if (end != NULL)
-       {
-               gtk_text_buffer_get_iter_at_mark (region->buffer, end, sr->end);
-       }
-
-       return TRUE;
-}
-
 GtkSourceRegion *
 gtk_source_region_intersect (GtkSourceRegion   *region,
                             const GtkTextIter *_start,
diff --git a/gtksourceview/gtksourceregion.h b/gtksourceview/gtksourceregion.h
index 804c97c..4d73727 100644
--- a/gtksourceview/gtksourceregion.h
+++ b/gtksourceview/gtksourceregion.h
@@ -76,15 +76,6 @@ gboolean             gtk_source_region_get_bounds            (GtkSourceRegion *region,
                                                                 GtkTextIter     *end);
 
 GTK_SOURCE_INTERNAL
-guint                  gtk_source_region_get_subregion_count   (GtkSourceRegion *region);
-
-GTK_SOURCE_INTERNAL
-gboolean               gtk_source_region_nth_subregion         (GtkSourceRegion *region,
-                                                                guint            subregion,
-                                                                GtkTextIter     *start,
-                                                                GtkTextIter     *end);
-
-GTK_SOURCE_INTERNAL
 void                   gtk_source_region_get_start_region_iter (GtkSourceRegion     *region,
                                                                 GtkSourceRegionIter *iter);
 
diff --git a/testsuite/test-region.c b/testsuite/test-region.c
index 2c4dc7a..3f5d808 100644
--- a/testsuite/test-region.c
+++ b/testsuite/test-region.c
@@ -139,29 +139,15 @@ test_region (void)
 
        while (!gtk_source_region_iter_is_end (&reg_iter))
        {
-               GtkTextIter s, e, s1, e1;
+               GtkTextIter s, e;
 
                gtk_source_region_iter_get_subregion (&reg_iter,
                                                      &s, &e);
-               gtk_source_region_nth_subregion (region, i, &s1, &e1);
 
-               if (!gtk_text_iter_equal (&s, &s1) ||
-                   !gtk_text_iter_equal (&e, &e1))
-               {
-                       g_print ("problem iterating\n");
-                       g_assert_not_reached ();
-               }
-
-               ++i;
+               i++;
                gtk_source_region_iter_next (&reg_iter);
        }
 
-       if (i != gtk_source_region_get_subregion_count (region))
-       {
-               g_print ("problem iterating all subregions\n");
-               g_assert_not_reached ();
-       }
-
        g_print ("iterated %u subregions\n", i);
 
        gtk_source_region_destroy (region);


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