mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 15:36:17 +01:00
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:
parent
496157ffd3
commit
f065d7d60e
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user