Updating branch refs/heads/master to a7a1dd4292b87384d7edae6d3f9995df2668fab0 (commit) from 610f0964b759a26944bca705dad5061f1fe0ba04 (commit)
commit a7a1dd4292b87384d7edae6d3f9995df2668fab0 Author: Jannis Pohlmann <jan...@xfce.org> Date: Wed Oct 21 11:50:07 2009 +0200 Update cache with tumbler_registry_update_supported() only when needed. We'll probably have to deal with a lot of specialized thumbnailers on Maemo and a lot of thumbnailer plugins on the desktop, and since tumbler_registry_update_supported() is VERY expensive, we should only call it when necessary. tumblerd/main.c | 3 + tumblerd/tumbler-registry.c | 278 +++++++++++++++++++++---------------------- tumblerd/tumbler-registry.h | 1 + 3 files changed, 140 insertions(+), 142 deletions(-) diff --git a/tumblerd/main.c b/tumblerd/main.c index 59fa0cf..93ae340 100644 --- a/tumblerd/main.c +++ b/tumblerd/main.c @@ -131,6 +131,9 @@ main (int argc, /* drop the reference on the provider factory */ g_object_unref (provider_factory); + /* update the URI schemes / MIME types supported information */ + tumbler_registry_update_supported (registry); + /* try to load specialized thumbnailers and exit if that fails */ if (!tumbler_registry_load (registry, &error)) { diff --git a/tumblerd/tumbler-registry.c b/tumblerd/tumbler-registry.c index d2b76f9..ecc0450 100644 --- a/tumblerd/tumbler-registry.c +++ b/tumblerd/tumbler-registry.c @@ -199,9 +199,6 @@ tumbler_registry_unregister (TumblerThumbnailer *thumbnailer, thumbnailer); g_mutex_unlock (registry->mutex); - - /* update the cache of supported URI schemes and MIME types */ - tumbler_registry_update_supported_cache (registry); } @@ -281,142 +278,6 @@ static void tumbler_registry_list_free (gpointer data) -static void -free_pair (gpointer data) -{ - g_slice_free1 (2 * sizeof (const gchar *), data); -} - - - -static void -tumbler_registry_update_supported_cache (TumblerRegistry *registry) -{ - GHashTableIter iter; - GHashTable *unique_pairs; - GSList *used_strings = NULL; - GList *thumbnailers; - GList *lp; - const gchar **pair; - GString *pair_string; - GStrv mime_types; - GStrv uri_schemes; - gint n; - gint u; - - g_return_if_fail (TUMBLER_IS_REGISTRY (registry)); - - g_mutex_lock (registry->mutex); - - /* free the old cache */ - g_strfreev (registry->uri_schemes); - registry->uri_schemes = NULL; - g_strfreev (registry->mime_types); - registry->mime_types = NULL; - - /* get a list of all active thumbnailers */ - thumbnailers = tumbler_registry_get_thumbnailers_internal (registry); - - g_mutex_unlock (registry->mutex); - - /* abort if there are no thumbnailers */ - if (thumbnailers == NULL) - return; - - /* create a hash table to collect unique URI scheme / MIME type pairs */ - unique_pairs = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) free_pair); - - /* iterate over all of them */ - for (lp = thumbnailers; lp != NULL; lp = lp->next) - { - /* determine the MIME types & URI schemes supported by the current thumbnailer */ - mime_types = tumbler_thumbnailer_get_mime_types (lp->data); - uri_schemes = tumbler_thumbnailer_get_uri_schemes (lp->data); - - /* insert all MIME types & URI schemes into the hash table */ - for (n = 0; - mime_types != NULL && uri_schemes != NULL && mime_types[n] != NULL; - ++n) - { - /* remember the MIME type so that we can later reuse it without copying */ - used_strings = g_slist_prepend (used_strings, mime_types[n]); - - for (u = 0; uri_schemes[u] != NULL; ++u) - { - /* remember the URI scheme for this pair so that we can later reuse it - * 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]); - - /* allocate a pair with the current URI scheme and MIME type */ - pair = g_slice_alloc (2 * sizeof (const gchar *)); - - /* we can now reuse the strings */ - pair[0] = uri_schemes[u]; - pair[1] = mime_types[n]; - - /* combine the two to a unique pair identifier */ - pair_string = g_string_new (pair[0]); - g_string_append_c (pair_string, '-'); - g_string_append (pair_string, pair[1]); - - /* remember the pair in the hash table */ - g_hash_table_insert (unique_pairs, pair_string->str, pair); - - /* free the pair string */ - g_string_free (pair_string, FALSE); - } - } - - /* free MIME types & URI schemes array. Their contents are stored in - * used_strings and are freed later */ - g_free (mime_types); - g_free (uri_schemes); - } - - /* relase the thumbnailer list */ - g_list_foreach (thumbnailers, (GFunc) g_object_unref, NULL); - g_list_free (thumbnailers); - - n = g_hash_table_size (unique_pairs); - - g_mutex_lock (registry->mutex); - - /* allocate a string array for the URI scheme / MIME type pairs */ - registry->uri_schemes = g_new0 (gchar *, n+1); - registry->mime_types = g_new0 (gchar *, n+1); - - /* insert all unique URI scheme / MIME type pairs into string arrays */ - n = 0; - g_hash_table_iter_init (&iter, unique_pairs); - while (g_hash_table_iter_next (&iter, NULL, (gpointer) &pair)) - { - /* fill the cache arrays with copied values */ - registry->uri_schemes[n] = g_strdup (pair[0]); - registry->mime_types[n] = g_strdup (pair[1]); - - ++n; - } - - /* NULL-terminate the arrays */ - registry->uri_schemes[n] = NULL; - registry->mime_types[n] = NULL; - - g_mutex_unlock (registry->mutex); - - /* destroy the hash table we used */ - 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); -} - - - static GList * tumbler_registry_get_thumbnailers_internal (TumblerRegistry *registry) { @@ -545,9 +406,6 @@ tumbler_registry_add (TumblerRegistry *registry, g_strfreev (hash_keys); g_mutex_unlock (registry->mutex); - - /* update the cached URI schemes / MIME types */ - tumbler_registry_update_supported_cache (registry); } @@ -628,6 +486,142 @@ tumbler_registry_get_thumbnailer_array (TumblerRegistry *registry, +static void +free_pair (gpointer data) +{ + g_slice_free1 (2 * sizeof (const gchar *), data); +} + + + +void +tumbler_registry_update_supported (TumblerRegistry *registry) +{ + GHashTableIter iter; + GHashTable *unique_pairs; + GSList *used_strings = NULL; + GList *thumbnailers; + GList *lp; + const gchar **pair; + GString *pair_string; + GStrv mime_types; + GStrv uri_schemes; + gint n; + gint u; + + g_return_if_fail (TUMBLER_IS_REGISTRY (registry)); + + g_mutex_lock (registry->mutex); + + /* free the old cache */ + g_strfreev (registry->uri_schemes); + registry->uri_schemes = NULL; + g_strfreev (registry->mime_types); + registry->mime_types = NULL; + + /* get a list of all active thumbnailers */ + thumbnailers = tumbler_registry_get_thumbnailers_internal (registry); + + g_mutex_unlock (registry->mutex); + + /* abort if there are no thumbnailers */ + if (thumbnailers == NULL) + return; + + /* create a hash table to collect unique URI scheme / MIME type pairs */ + unique_pairs = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) free_pair); + + /* iterate over all of them */ + for (lp = thumbnailers; lp != NULL; lp = lp->next) + { + /* determine the MIME types & URI schemes supported by the current thumbnailer */ + mime_types = tumbler_thumbnailer_get_mime_types (lp->data); + uri_schemes = tumbler_thumbnailer_get_uri_schemes (lp->data); + + /* insert all MIME types & URI schemes into the hash table */ + for (n = 0; + mime_types != NULL && uri_schemes != NULL && mime_types[n] != NULL; + ++n) + { + /* remember the MIME type so that we can later reuse it without copying */ + used_strings = g_slist_prepend (used_strings, mime_types[n]); + + for (u = 0; uri_schemes[u] != NULL; ++u) + { + /* remember the URI scheme for this pair so that we can later reuse it + * 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]); + + /* allocate a pair with the current URI scheme and MIME type */ + pair = g_slice_alloc (2 * sizeof (const gchar *)); + + /* we can now reuse the strings */ + pair[0] = uri_schemes[u]; + pair[1] = mime_types[n]; + + /* combine the two to a unique pair identifier */ + pair_string = g_string_new (pair[0]); + g_string_append_c (pair_string, '-'); + g_string_append (pair_string, pair[1]); + + /* remember the pair in the hash table */ + g_hash_table_insert (unique_pairs, pair_string->str, pair); + + /* free the pair string */ + g_string_free (pair_string, FALSE); + } + } + + /* free MIME types & URI schemes array. Their contents are stored in + * used_strings and are freed later */ + g_free (mime_types); + g_free (uri_schemes); + } + + /* relase the thumbnailer list */ + g_list_foreach (thumbnailers, (GFunc) g_object_unref, NULL); + g_list_free (thumbnailers); + + n = g_hash_table_size (unique_pairs); + + g_mutex_lock (registry->mutex); + + /* allocate a string array for the URI scheme / MIME type pairs */ + registry->uri_schemes = g_new0 (gchar *, n+1); + registry->mime_types = g_new0 (gchar *, n+1); + + /* insert all unique URI scheme / MIME type pairs into string arrays */ + n = 0; + g_hash_table_iter_init (&iter, unique_pairs); + while (g_hash_table_iter_next (&iter, NULL, (gpointer) &pair)) + { + /* fill the cache arrays with copied values */ + registry->uri_schemes[n] = g_strdup (pair[0]); + registry->mime_types[n] = g_strdup (pair[1]); + + ++n; + } + + /* NULL-terminate the arrays */ + registry->uri_schemes[n] = NULL; + registry->mime_types[n] = NULL; + + g_mutex_unlock (registry->mutex); + + /* destroy the hash table we used */ + 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); +} + + + void tumbler_registry_get_supported (TumblerRegistry *registry, const gchar *const **uri_schemes, diff --git a/tumblerd/tumbler-registry.h b/tumblerd/tumbler-registry.h index acac8c3..011fd04 100644 --- a/tumblerd/tumbler-registry.h +++ b/tumblerd/tumbler-registry.h @@ -47,6 +47,7 @@ TumblerThumbnailer **tumbler_registry_get_thumbnailer_array (TumblerRegistry const GStrv uris, const GStrv mime_hints, gint *length) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +void tumbler_registry_update_supported (TumblerRegistry *registry); void tumbler_registry_get_supported (TumblerRegistry *registry, const gchar *const **uri_schemes, const gchar *const **mime_types); _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits