From: Mathieu Duponchelle Date: Wed, 11 Apr 2018 11:44:33 +0000 (+0200) Subject: gstqueuearray: make find() return a 0-based index X-Git-Tag: 1.16.2~412 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=68761eecaec51ed403a0e6bebe75584e094ec804;p=platform%2Fupstream%2Fgstreamer.git gstqueuearray: make find() return a 0-based index And make the drop() functions expect a 0-based index too, this addresses a longstanding FIXME. This will not break backward compatibility, because the drop() functions were previously only meant to be used with the index returned by find(). https://bugzilla.gnome.org/show_bug.cgi?id=795156 --- diff --git a/libs/gst/base/gstqueuearray.c b/libs/gst/base/gstqueuearray.c index c52ee39..3434c81 100644 --- a/libs/gst/base/gstqueuearray.c +++ b/libs/gst/base/gstqueuearray.c @@ -476,6 +476,8 @@ gst_queue_array_drop_struct (GstQueueArray * array, guint idx, guint elt_size; g_return_val_if_fail (array != NULL, FALSE); + idx = (array->head + idx) % array->size; + g_return_val_if_fail (array->length > 0, FALSE); g_return_val_if_fail (idx < array->size, FALSE); @@ -581,11 +583,6 @@ gst_queue_array_drop_element (GstQueueArray * array, guint idx) * with @func or by looking up @data if no compare function @func is provided, * and returning the index of the found element. * - * Note that the index is not 0-based, but an internal index number with a - * random offset. The index can be used in connection with - * gst_queue_array_drop_element(). FIXME: return index 0-based and make - * gst_queue_array_drop_element() take a 0-based index. - * * Returns: Index of the found element or -1 if nothing was found. * * Since: 1.2 @@ -611,13 +608,13 @@ gst_queue_array_find (GstQueueArray * array, GCompareFunc func, gpointer data) for (i = 0; i < array->length; i++) { p_element = array->array + ((i + array->head) % array->size) * elt_size; if (func (*(gpointer *) p_element, data) == 0) - return (i + array->head) % array->size; + return i; } } else { for (i = 0; i < array->length; i++) { p_element = array->array + ((i + array->head) % array->size) * elt_size; if (*(gpointer *) p_element == data) - return (i + array->head) % array->size; + return i; } }