[goffice] glib: use some functions added to glib in the meantime.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] glib: use some functions added to glib in the meantime.
- Date: Tue, 8 May 2018 15:28:11 +0000 (UTC)
commit d96b9c51b83a8517608fff07e0e5859b8ad51714
Author: Morten Welinder <terra gnome org>
Date: Tue May 8 11:27:00 2018 -0400
glib: use some functions added to glib in the meantime.
g_ptr_array_insert ~ go_ptr_array_insert
g_slist_copy_deep ~ go_slist_map
configure.ac | 8 +++---
goffice/utils/go-glib-extras.c | 44 ++++++++++++++-------------------------
goffice/utils/go-glib-extras.h | 11 +++++++--
3 files changed, 28 insertions(+), 35 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3f6b735..c7a1fc0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -117,10 +117,10 @@ PKG_PROG_PKG_CONFIG
dnl *****************************
goffice_reqs="
- glib-2.0 >= 2.38.0
- gobject-2.0 >= 2.38.0
- gmodule-2.0 >= 2.38.0
- gio-2.0 >= 2.38.0
+ glib-2.0 >= 2.40.0
+ gobject-2.0 >= 2.40.0
+ gmodule-2.0 >= 2.40.0
+ gio-2.0 >= 2.40.0
libgsf-1 >= 1.14.24
libxml-2.0 >= 2.4.12
pango >= 1.24.0
diff --git a/goffice/utils/go-glib-extras.c b/goffice/utils/go-glib-extras.c
index f6b063d..779fe40 100644
--- a/goffice/utils/go-glib-extras.c
+++ b/goffice/utils/go-glib-extras.c
@@ -40,12 +40,6 @@
#include <unistd.h>
#endif
-static void
-cb_hash_collect_keys (gpointer key, gpointer value, GSList **accum)
-{
- *accum = g_slist_prepend (*accum, key);
-}
-
/**
* go_hash_keys:
* @hash: #GHashTable
@@ -54,13 +48,20 @@ cb_hash_collect_keys (gpointer key, gpointer value, GSList **accum)
*
* Returns: (element-type void) (transfer container): a list which the
* caller needs to free. The content has not additional references added
+ *
+ * Note: consider using g_hash_table_get_keys instead.
**/
GSList *
go_hash_keys (GHashTable *hash)
{
+ GHashTableIter hiter;
GSList *accum = NULL;
- g_hash_table_foreach (hash,
- (GHFunc )cb_hash_collect_keys, &accum);
+ gpointer key;
+
+ g_hash_table_iter_init (&hiter, hash);
+ while (g_hash_table_iter_next (&hiter, &key, NULL))
+ accum = g_slist_prepend (accum, key);
+
return accum;
}
@@ -73,23 +74,14 @@ go_hash_keys (GHashTable *hash)
* @index: where to insert @value
*
* Inserts a pointer inside an existing array.
+ *
+ * Note: consider using g_ptr_array_insert instead, but watch out of the
+ * argument order.
**/
-
void
go_ptr_array_insert (GPtrArray *array, gpointer value, int index)
{
- if (index < (int)array->len) {
- int i = array->len - 1;
- gpointer last = g_ptr_array_index (array, i);
- g_ptr_array_add (array, last);
-
- while (i-- > index) {
- gpointer tmp = g_ptr_array_index (array, i);
- g_ptr_array_index (array, i + 1) = tmp;
- }
- g_ptr_array_index (array, index) = value;
- } else
- g_ptr_array_add (array, value);
+ g_ptr_array_insert (array, index, value);
}
/**
@@ -124,17 +116,13 @@ go_slist_create (gconstpointer item1, ...)
*
* The ownership of the list elements depends on map_func.
* Returns: (element-type void) (transfer container): the mapped list
+ *
+ * Note: consider using g_slist_copy_deep instead.
**/
GSList *
go_slist_map (GSList const *list, GOMapFunc map_func)
{
- GSList *list_copy = NULL;
-
- GO_SLIST_FOREACH (list, void, value,
- GO_SLIST_PREPEND (list_copy, map_func (value))
- );
-
- return g_slist_reverse (list_copy);
+ return g_slist_copy_deep ((GSList *)list, (GCopyFunc)map_func, NULL);
}
/**
diff --git a/goffice/utils/go-glib-extras.h b/goffice/utils/go-glib-extras.h
index 99f9edf..a9b67f9 100644
--- a/goffice/utils/go-glib-extras.h
+++ b/goffice/utils/go-glib-extras.h
@@ -7,15 +7,20 @@ G_BEGIN_DECLS
/* Misc convenience routines that would be nice to have in glib */
-typedef gpointer (*GOMapFunc) (gpointer value);
-
+#ifndef GOFFICE_DISABLE_DEPRECATED
+GOFFICE_DEPRECATED_FOR(g_ptr_array_insert)
void go_ptr_array_insert (GPtrArray *array, gpointer value, int index);
+#endif
GSList *go_hash_keys (GHashTable *hash);
+#ifndef GOFFICE_DISABLE_DEPRECATED
+typedef gpointer (*GOMapFunc) (gpointer value);
+GOFFICE_DEPRECATED_FOR(g_slist_copy_deep)
GSList *go_slist_map (GSList const *list, GOMapFunc map_func);
+#endif
GSList *go_slist_create (gconstpointer item1, ...);
-#define go_string_slist_copy(list) go_slist_map (list, (GOMapFunc) g_strdup)
+#define go_string_slist_copy(list) g_slist_copy_deep (list, (GCopyFunc)g_strdup, NULL)
GSList *go_strsplit_to_slist (char const *str, gchar delimiter);
#define GO_SLIST_FOREACH(list,valtype,val,stmnt) \
G_STMT_START { \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]