[gtk/wip/otte/for-master: 8/10] stringlist: Remove n_additions argument from gtk_string_list_splice()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/for-master: 8/10] stringlist: Remove n_additions argument from gtk_string_list_splice()
- Date: Sun, 5 Jul 2020 01:00:47 +0000 (UTC)
commit c4e4de36f60881a8f29287dc612f2a8e055d12e3
Author: Benjamin Otte <otte redhat com>
Date: Tue Jun 30 19:36:51 2020 +0200
stringlist: Remove n_additions argument from gtk_string_list_splice()
char ** arrays are null-terminated everywhere, so make sure they are in
splice(), too.
Also fix the argument to be a const char * const * like in the
constructor.
gtk/gtkstringlist.c | 31 +++++++++++++++----------------
gtk/gtkstringlist.h | 27 +++++++++++++--------------
testsuite/gtk/stringlist.c | 2 +-
3 files changed, 29 insertions(+), 31 deletions(-)
---
diff --git a/gtk/gtkstringlist.c b/gtk/gtkstringlist.c
index e58a0fe6b6..a3e2af5f68 100644
--- a/gtk/gtkstringlist.c
+++ b/gtk/gtkstringlist.c
@@ -449,11 +449,10 @@ gtk_string_list_new (const char * const *strings)
* @self: a #GtkStringList
* @position: the position at which to make the change
* @n_removals: the number of strings to remove
- * @additions: (array length=n_additions): the strings to add
- * @n_additions: the number of items to add
+ * @additions: (array zero-terminated=1) (nullable): The strings to add
*
- * Changes @self by removing @n_removals strings and adding @n_additions
- * strings to it.
+ * Changes @self by removing @n_removals strings and adding @additions
+ * to it.
*
* This function is more efficient than gtk_string_list_insert() and
* gtk_string_list_remove(), because it only emits
@@ -466,14 +465,13 @@ gtk_string_list_new (const char * const *strings)
* of the list at the time this function is called).
*/
void
-gtk_string_list_splice (GtkStringList *self,
- guint position,
- guint n_removals,
- const char **additions,
- guint n_additions)
+gtk_string_list_splice (GtkStringList *self,
+ guint position,
+ guint n_removals,
+ const char * const *additions)
{
GSequenceIter *it;
- guint n_items;
+ guint add, n_items;
g_return_if_fail (GTK_IS_STRING_LIST (self));
g_return_if_fail (position + n_removals >= position); /* overflow */
@@ -493,17 +491,18 @@ gtk_string_list_splice (GtkStringList *self,
it = end;
}
- if (n_additions)
+ if (additions)
{
- gint i;
-
- for (i = 0; i < n_additions; i++)
+ for (add = 0; additions[add]; add++)
{
- g_sequence_insert_before (it, gtk_string_object_new (additions[i]));
+ g_sequence_insert_before (it, gtk_string_object_new (additions[add]));
}
}
+ else
+ add = 0;
- g_list_model_items_changed (G_LIST_MODEL (self), position, n_removals, n_additions);
+ if (n_removals || add)
+ g_list_model_items_changed (G_LIST_MODEL (self), position, n_removals, add);
}
/**
diff --git a/gtk/gtkstringlist.h b/gtk/gtkstringlist.h
index 0a29612ef8..17be87864b 100644
--- a/gtk/gtkstringlist.h
+++ b/gtk/gtkstringlist.h
@@ -45,30 +45,29 @@ GDK_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (GtkStringList, gtk_string_list, GTK, STRING_LIST, GObject)
GDK_AVAILABLE_IN_ALL
-GtkStringList * gtk_string_list_new (const char * const *strings);
+GtkStringList * gtk_string_list_new (const char * const *strings);
GDK_AVAILABLE_IN_ALL
-void gtk_string_list_append (GtkStringList *self,
- const char *string);
+void gtk_string_list_append (GtkStringList *self,
+ const char *string);
GDK_AVAILABLE_IN_ALL
-void gtk_string_list_take (GtkStringList *self,
- char *string);
+void gtk_string_list_take (GtkStringList *self,
+ char *string);
GDK_AVAILABLE_IN_ALL
-void gtk_string_list_remove (GtkStringList *self,
- guint position);
+void gtk_string_list_remove (GtkStringList *self,
+ guint position);
GDK_AVAILABLE_IN_ALL
-void gtk_string_list_splice (GtkStringList *self,
- guint position,
- guint n_removals,
- const char **additions,
- guint n_additions);
+void gtk_string_list_splice (GtkStringList *self,
+ guint position,
+ guint n_removals,
+ const char * const *additions);
GDK_AVAILABLE_IN_ALL
-const char * gtk_string_list_get_string (GtkStringList *self,
- guint position);
+const char * gtk_string_list_get_string (GtkStringList *self,
+ guint position);
G_END_DECLS
diff --git a/testsuite/gtk/stringlist.c b/testsuite/gtk/stringlist.c
index 5b6256f93f..12169be13e 100644
--- a/testsuite/gtk/stringlist.c
+++ b/testsuite/gtk/stringlist.c
@@ -184,7 +184,7 @@ test_splice (void)
assert_model (list, "a b c d e");
- gtk_string_list_splice (list, 2, 2, (const char *[]){ "x", "y", "z" }, 3);
+ gtk_string_list_splice (list, 2, 2, (const char *[]){ "x", "y", "z", NULL });
assert_model (list, "a b x y z e");
assert_changes (list, "2-2+3");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]