[gnome-photos] fetch-collection-state-job: Avoid O(n) logic
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] fetch-collection-state-job: Avoid O(n) logic
- Date: Tue, 10 Nov 2015 11:25:16 +0000 (UTC)
commit ff54cbf90fcf7459dca654235bcca415f2b3e755
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Oct 30 14:15:41 2015 +0100
fetch-collection-state-job: Avoid O(n) logic
Let's not iterate over the list twice - once to create it and again to
find out the length, when we only need to do it once.
https://bugzilla.gnome.org/show_bug.cgi?id=757363
src/photos-fetch-collection-state-job.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/src/photos-fetch-collection-state-job.c b/src/photos-fetch-collection-state-job.c
index 009c6e9..e15c385 100644
--- a/src/photos-fetch-collection-state-job.c
+++ b/src/photos-fetch-collection-state-job.c
@@ -106,27 +106,28 @@ photos_fetch_collection_state_job_emit_callback (PhotosFetchCollectionStateJob *
{
GHashTableIter iter2;
GList *collections_for_item;
- GList *keys;
PhotosBaseItem *item;
gboolean found = FALSE;
gboolean hidden = FALSE;
gboolean not_found = FALSE;
const gchar *item_idx;
gint state = PHOTOS_COLLECTION_STATE_NORMAL;
+ gpointer *keys;
+ guint length;
/* If the only object we are fetching collection state for is a
* collection itself, hide this if it is the same collection.
*/
- keys = g_hash_table_get_keys (self->collections_for_items);
- if (g_list_length (keys) == 1)
+ keys = g_hash_table_get_keys_as_array (self->collections_for_items, &length);
+ if (length == 1)
{
- item_idx = (gchar *) keys->data;
+ item_idx = ((gchar **) keys)[0];
item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->item_mngr, item_idx));
if (g_strcmp0 (photos_filterable_get_id (PHOTOS_FILTERABLE (item)),
photos_filterable_get_id (PHOTOS_FILTERABLE (collection))) == 0)
hidden = TRUE;
}
- g_list_free (keys);
+ g_free (keys);
g_hash_table_iter_init (&iter2, self->collections_for_items);
while (g_hash_table_iter_next (&iter2, (gpointer *) &item_idx, (gpointer *) &collections_for_item))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]