Optimize list iterations in KatzeArray

This commit is contained in:
Christian Dywan 2009-03-31 03:25:48 +02:00
parent 7cddd8ade3
commit fb37688db3

View file

@ -207,14 +207,15 @@ static void
katze_array_finalize (GObject* object) katze_array_finalize (GObject* object)
{ {
KatzeArray* array; KatzeArray* array;
guint n, i; guint i;
array = KATZE_ARRAY (object); array = KATZE_ARRAY (object);
if (katze_array_is_a (array, G_TYPE_OBJECT)) if (katze_array_is_a (array, G_TYPE_OBJECT))
{ {
n = g_list_length (array->items); gpointer item;
for (i = 0; i < n; i++) i = 0;
g_object_unref (g_list_nth_data (array->items, i)); while ((item = g_list_nth_data (array->items, i++)))
g_object_unref (item);
} }
g_list_free (array->items); g_list_free (array->items);
@ -371,22 +372,16 @@ gpointer
katze_array_find_token (KatzeArray* array, katze_array_find_token (KatzeArray* array,
const gchar* token) const gchar* token)
{ {
guint n, i; guint i;
gpointer item; gpointer item;
const gchar* found_token;
g_return_val_if_fail (KATZE_IS_ARRAY (array), NULL);
if (!katze_array_is_a (array, G_TYPE_OBJECT)) if (!katze_array_is_a (array, G_TYPE_OBJECT))
return NULL; return NULL;
n = g_list_length (array->items); i = 0;
for (i = 0; i < n; i++) while ((item = g_list_nth_data (array->items, i++)))
{ {
item = g_list_nth_data (array->items, i); const gchar* found_token = katze_item_get_token ((KatzeItem*)item);
if (!g_type_is_a (G_OBJECT_TYPE (item), KATZE_TYPE_ITEM))
continue;
found_token = katze_item_get_token ((KatzeItem*)item);
if (!g_strcmp0 (found_token, token)) if (!g_strcmp0 (found_token, token))
return item; return item;
} }