[glib: 1/2] gconvert: Use a pointer array in extract_uris
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] gconvert: Use a pointer array in extract_uris
- Date: Fri, 3 Jul 2020 20:44:26 +0000 (UTC)
commit 3ef229fd03c6a14b76465828238fc738725ad4d7
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Fri Jul 3 15:10:40 2020 -0400
gconvert: Use a pointer array in extract_uris
Use a GPtrArray instead of a GSList in g_uri_list_extract_uris().
glib/gconvert.c | 25 +++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)
---
diff --git a/glib/gconvert.c b/glib/gconvert.c
index c5857df1c..452c852f0 100644
--- a/glib/gconvert.c
+++ b/glib/gconvert.c
@@ -1806,12 +1806,10 @@ g_filename_to_uri (const gchar *filename,
gchar **
g_uri_list_extract_uris (const gchar *uri_list)
{
- GSList *uris, *u;
+ GPtrArray *uris;
const gchar *p, *q;
- gchar **result;
- gint n_uris = 0;
- uris = NULL;
+ uris = g_ptr_array_new ();
p = uri_list;
@@ -1840,26 +1838,17 @@ g_uri_list_extract_uris (const gchar *uri_list)
q--;
if (q > p)
- {
- uris = g_slist_prepend (uris, g_strndup (p, q - p + 1));
- n_uris++;
- }
- }
- }
+ g_ptr_array_add (uris, g_strndup (p, q - p + 1));
+ }
+ }
p = strchr (p, '\n');
if (p)
p++;
}
- result = g_new (gchar *, n_uris + 1);
-
- result[n_uris--] = NULL;
- for (u = uris; u; u = u->next)
- result[n_uris--] = u->data;
+ g_ptr_array_add (uris, NULL);
- g_slist_free (uris);
-
- return result;
+ return (gchar **) g_ptr_array_free (uris, FALSE);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]