[Xfce4-commits] <tumbler:master> Work with an array to store the strings.
Nick Schermer
noreply at xfce.org
Sat Dec 8 00:20:05 CET 2012
Updating branch refs/heads/master
to 2165c4239697a905fdd3e46037baa977c05e4fb1 (commit)
from 0093f278c4dfe45e404ae502aa0e3c817f7a38fc (commit)
commit 2165c4239697a905fdd3e46037baa977c05e4fb1
Author: Nick Schermer <nick at xfce.org>
Date: Fri Dec 7 23:54:43 2012 +0100
Work with an array to store the strings.
Called a lot, so array is a bit more efficient than.
tumblerd/tumbler-registry.c | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/tumblerd/tumbler-registry.c b/tumblerd/tumbler-registry.c
index 5f8c8ab..c75ca61 100644
--- a/tumblerd/tumbler-registry.c
+++ b/tumblerd/tumbler-registry.c
@@ -469,7 +469,7 @@ tumbler_registry_update_supported (TumblerRegistry *registry)
{
GHashTableIter iter;
GHashTable *unique_pairs;
- GSList *used_strings = NULL;
+ GPtrArray *used_strings;
GList *thumbnailers;
GList *lp;
const gchar **pair;
@@ -507,6 +507,9 @@ tumbler_registry_update_supported (TumblerRegistry *registry)
(GDestroyNotify) g_free,
(GDestroyNotify) free_pair);
+ /* prepare array */
+ used_strings = g_ptr_array_sized_new (150);
+
/* iterate over all of them */
for (lp = thumbnailers; lp != NULL; lp = lp->next)
{
@@ -523,7 +526,7 @@ tumbler_registry_update_supported (TumblerRegistry *registry)
++n)
{
/* remember the MIME type so that we can later reuse it without copying */
- used_strings = g_slist_prepend (used_strings, mime_types[n]);
+ g_ptr_array_add (used_strings, mime_types[n]);
for (u = 0; uri_schemes[u] != NULL; ++u)
{
@@ -531,7 +534,7 @@ tumbler_registry_update_supported (TumblerRegistry *registry)
* without copying. Only remember it once (n==0) to avoid segmentation
* faults when freeing the list */
if (n == 0)
- used_strings = g_slist_prepend (used_strings, uri_schemes[u]);
+ g_ptr_array_add (used_strings, uri_schemes[u]);
/* allocate a pair with the current URI scheme and MIME type */
pair = g_slice_alloc (2 * sizeof (const gchar *));
@@ -593,8 +596,8 @@ tumbler_registry_update_supported (TumblerRegistry *registry)
g_hash_table_unref (unique_pairs);
/* free all strings we used but haven't freed yet */
- g_slist_foreach (used_strings, (GFunc) g_free, NULL);
- g_slist_free (used_strings);
+ g_ptr_array_foreach (used_strings, (GFunc) g_free, NULL);
+ g_ptr_array_free (used_strings, TRUE);
}
More information about the Xfce4-commits
mailing list