gstqueuearray: make find() return a 0-based index
authorMathieu Duponchelle <mathieu@centricular.com>
Wed, 11 Apr 2018 11:44:33 +0000 (13:44 +0200)
committerMathieu Duponchelle <mathieu@centricular.com>
Fri, 13 Apr 2018 22:01:35 +0000 (00:01 +0200)
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

libs/gst/base/gstqueuearray.c

index c52ee39..3434c81 100644 (file)
@@ -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;
     }
   }