[gnome-photos/wip/rishi/manager-model: 5/8] base-manager: Avoid O(n) logic
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/manager-model: 5/8] base-manager: Avoid O(n) logic
- Date: Sat, 5 Nov 2016 14:59:26 +0000 (UTC)
commit 70ecc0edc6acb9d5678aecdad402b7bac5f460f6
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Nov 5 13:28:45 2016 +0100
base-manager: Avoid O(n) logic
GHashTableIter is more efficient because we don't have to iterate over
every entry in the hash table to create the list of values.
src/photos-base-manager.c | 17 +++++++----------
1 files changed, 7 insertions(+), 10 deletions(-)
---
diff --git a/src/photos-base-manager.c b/src/photos-base-manager.c
index 2cca3a8..ff2f61b 100644
--- a/src/photos-base-manager.c
+++ b/src/photos-base-manager.c
@@ -362,9 +362,10 @@ gchar *
photos_base_manager_get_all_filter (PhotosBaseManager *self)
{
PhotosBaseManagerPrivate *priv;
- GList *l;
- GList *values;
+ GHashTableIter iter;
+ GObject *object;
const gchar *blank = "(true)";
+ const gchar *id;
gchar *filter;
gchar **strv;
gchar *tmp;
@@ -373,21 +374,18 @@ photos_base_manager_get_all_filter (PhotosBaseManager *self)
priv = photos_base_manager_get_instance_private (self);
- values = g_hash_table_get_values (priv->objects);
length = photos_base_manager_get_objects_count (self);
strv = (gchar **) g_malloc0_n (length + 1, sizeof (gchar *));
- for (i = 0, l = values; l != NULL; l = l->next)
+ i = 0;
+ g_hash_table_iter_init (&iter, priv->objects);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &id, (gpointer *) &object))
{
- PhotosFilterable *filterable = PHOTOS_FILTERABLE (l->data);
- const gchar *id;
-
- id = photos_filterable_get_id (filterable);
if (g_strcmp0 (id, "all") != 0)
{
gchar *str;
- str = photos_filterable_get_filter (filterable);
+ str = photos_filterable_get_filter (PHOTOS_FILTERABLE (object));
if (g_strcmp0 (str, blank) == 0)
g_free (str);
else
@@ -409,7 +407,6 @@ photos_base_manager_get_all_filter (PhotosBaseManager *self)
filter = g_strconcat ("(", filter, ")", NULL);
g_free (tmp);
- g_list_free (values);
return filter;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]