Have g_queue_remove() return a boolean

g_queue_remove() should return a boolean so callers can verify that an
element was found and removed, as in the following example:

    if (g_queue_remove (queue, referenced_object))
        g_object_unref (referenced_object);

Similarly, g_queue_remove_all() should return the number of elements
found and removed.

https://bugzilla.gnome.org/show_bug.cgi?id=632294
This commit is contained in:
Matthew Barnes 2010-10-16 07:40:44 -04:00 committed by Matthias Clasen
parent 496157ffd3
commit f065d7d60e
2 changed files with 17 additions and 6 deletions

View File

@ -880,20 +880,24 @@ g_queue_index (GQueue *queue,
*
* Removes the first element in @queue that contains @data.
*
* Return value: %TRUE if @data was found and removed from @queue
*
* Since: 2.4
**/
void
gboolean
g_queue_remove (GQueue *queue,
gconstpointer data)
{
GList *link;
g_return_if_fail (queue != NULL);
g_return_val_if_fail (queue != NULL, FALSE);
link = g_list_find (queue->head, data);
if (link)
g_queue_delete_link (queue, link);
return (link != NULL);
}
/**
@ -903,15 +907,20 @@ g_queue_remove (GQueue *queue,
*
* Remove all elements whose data equals @data from @queue.
*
* Return value: the number of elements removed from @queue
*
* Since: 2.4
**/
void
guint
g_queue_remove_all (GQueue *queue,
gconstpointer data)
{
GList *list;
guint old_length;
g_return_if_fail (queue != NULL);
g_return_val_if_fail (queue != NULL, 0);
old_length = queue->length;
list = queue->head;
while (list)
@ -923,6 +932,8 @@ g_queue_remove_all (GQueue *queue,
list = next;
}
return (old_length - queue->length);
}
/**

View File

@ -85,9 +85,9 @@ gpointer g_queue_peek_nth (GQueue *queue,
guint n);
gint g_queue_index (GQueue *queue,
gconstpointer data);
void g_queue_remove (GQueue *queue,
gboolean g_queue_remove (GQueue *queue,
gconstpointer data);
void g_queue_remove_all (GQueue *queue,
guint g_queue_remove_all (GQueue *queue,
gconstpointer data);
void g_queue_insert_before (GQueue *queue,
GList *sibling,