[Xfce4-commits] <midori:master> Optimize list-based katze_array_ functions
Christian Dywan
noreply at xfce.org
Fri Feb 10 23:44:02 CET 2012
Updating branch refs/heads/master
to b6f86b0ca61ca567eab7b8493057d38afdc8be1f (commit)
from 9c323ff1498371e17f360815bcc42eaa3424dea1 (commit)
commit b6f86b0ca61ca567eab7b8493057d38afdc8be1f
Author: Christian Dywan <christian at twotoasts.de>
Date: Fri Feb 10 23:01:07 2012 +0100
Optimize list-based katze_array_ functions
katze/katze-array.c | 70 ++++++++++++++++++++++++---------------------------
1 files changed, 33 insertions(+), 37 deletions(-)
diff --git a/katze/katze-array.c b/katze/katze-array.c
index 49291d0..210a97f 100644
--- a/katze/katze-array.c
+++ b/katze/katze-array.c
@@ -112,7 +112,7 @@ _katze_array_clear (KatzeArray* array)
GObject* item;
while ((item = g_list_nth_data (array->items, 0)))
- katze_array_remove_item (array, item);
+ g_signal_emit (array, signals[REMOVE_ITEM], 0, item);
g_list_free (array->items);
array->items = NULL;
}
@@ -217,14 +217,11 @@ katze_array_init (KatzeArray* array)
static void
katze_array_finalize (GObject* object)
{
- KatzeArray* array;
- guint i;
- gpointer item;
+ KatzeArray* array = KATZE_ARRAY (object);
+ GList* items;
- array = KATZE_ARRAY (object);
- i = 0;
- while ((item = g_list_nth_data (array->items, i++)))
- g_object_unref (item);
+ for (items = array->items; items; items = g_list_next (items))
+ g_object_unref (items->data);
g_list_free (array->items);
G_OBJECT_CLASS (katze_array_parent_class)->finalize (object);
@@ -364,37 +361,39 @@ katze_array_get_item_index (KatzeArray* array,
/**
* katze_array_find_token:
* @array: a #KatzeArray
- * @token: a token string
+ * @token: a token string, or "token keywords" string
*
* Looks up an item in the array which has the specified token.
*
- * This function will silently fail if the type of the list
- * is not based on #GObject and only #KatzeItem children
- * are checked for their token, any other objects are skipped.
+ * This function will fail if the type of the list
+ * is not based on #KatzeItem children.
*
* Note that @token is by definition unique to one item.
*
+ * Since 0.4.4 @token can be a "token keywords" string.
+ *
* Return value: an item, or %NULL
**/
gpointer
katze_array_find_token (KatzeArray* array,
const gchar* token)
{
- guint i;
- gpointer item;
+ goffset token_length;
+ GList* items;
g_return_val_if_fail (KATZE_IS_ARRAY (array), NULL);
+ g_return_val_if_fail (katze_array_is_a (array, KATZE_TYPE_ITEM), NULL);
+ g_return_val_if_fail (token != NULL, NULL);
- i = 0;
- while ((item = g_list_nth_data (array->items, i++)))
- {
- const gchar* found_token;
+ token_length = strchr (token, ' ') - token;
+ if (token_length < 1)
+ token_length = strlen (token);
- if (!KATZE_IS_ITEM (item))
- continue;
- found_token = ((KatzeItem*)item)->token;
- if (!g_strcmp0 (found_token, token))
- return item;
+ for (items = array->items; items; items = g_list_next (items))
+ {
+ const gchar* found_token = ((KatzeItem*)items->data)->token;
+ if (found_token != NULL && !strncmp (token, found_token, token_length))
+ return items->data;
}
return NULL;
}
@@ -406,9 +405,8 @@ katze_array_find_token (KatzeArray* array,
*
* Looks up an item in the array which has the specified URI.
*
- * This function will silently fail if the type of the list
- * is not based on #GObject and only #KatzeItem children
- * are checked for their token, any other objects are skipped.
+ * This function will fail if the type of the list
+ * is not based on #KatzeItem children.
*
* Return value: an item, or %NULL
*
@@ -418,19 +416,17 @@ gpointer
katze_array_find_uri (KatzeArray* array,
const gchar* uri)
{
- guint i;
- gpointer item;
+ GList* items;
- i = 0;
- while ((item = g_list_nth_data (array->items, i++)))
- {
- const gchar* found_uri;
+ g_return_val_if_fail (KATZE_IS_ARRAY (array), NULL);
+ g_return_val_if_fail (katze_array_is_a (array, KATZE_TYPE_ITEM), NULL);
+ g_return_val_if_fail (uri != NULL, NULL);
- if (!KATZE_IS_ITEM (item))
- continue;
- found_uri = ((KatzeItem*)item)->uri;
- if (!g_strcmp0 (found_uri, uri))
- return item;
+ for (items = array->items; items; items = g_list_next (items))
+ {
+ const gchar* found_uri = ((KatzeItem*)items->data)->uri;
+ if (found_uri != NULL && !strcmp (found_uri, uri))
+ return items->data;
}
return NULL;
}
More information about the Xfce4-commits
mailing list