diff options
author | Timm Bäder <mail@baedert.org> | 2018-02-24 08:40:41 +0100 |
---|---|---|
committer | Timm Bäder <mail@baedert.org> | 2018-02-25 16:47:20 +0100 |
commit | dc1612b86568b58b88d9a25dc19871fc2b2b42f3 (patch) | |
tree | cbce2f9a5063098021f90bf78212deb3eac0b1ec /gdk | |
parent | 7d7045bc35db48acbd8f8ffbd133f975efb90848 (diff) | |
download | gtk+-dc1612b86568b58b88d9a25dc19871fc2b2b42f3.tar.gz |
contentsformat: Avoid a GPtrArray
We know how many items this array will have in advance, so just malloc
enough.
Diffstat (limited to 'gdk')
-rw-r--r-- | gdk/gdkcontentformats.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/gdk/gdkcontentformats.c b/gdk/gdkcontentformats.c index cd3293f0a3..95a8a608ae 100644 --- a/gdk/gdkcontentformats.c +++ b/gdk/gdkcontentformats.c @@ -147,18 +147,20 @@ GdkContentFormats * gdk_content_formats_new (const char **mime_types, guint n_mime_types) { - GPtrArray *array; guint i; + const char **mime_types_copy; if (n_mime_types == 0) return gdk_content_formats_new_take (NULL, 0, NULL, 0); - array = g_ptr_array_new (); + mime_types_copy = g_new (const char *, n_mime_types + 1); + for (i = 0; i < n_mime_types; i++) - g_ptr_array_add (array, (gpointer) g_intern_string (mime_types[i])); - g_ptr_array_add (array, NULL); + mime_types_copy[i] = g_intern_string (mime_types[i]); + + mime_types_copy[n_mime_types] = NULL; - return gdk_content_formats_new_take (NULL, 0, (const char **) g_ptr_array_free (array, FALSE), n_mime_types); + return gdk_content_formats_new_take (NULL, 0, mime_types_copy, n_mime_types); } /** |