[vlc-devel] [PATCH 3/7] randomizer: fix history cursor on insertion

Romain Vimont rom1v at videolabs.io
Thu May 16 17:50:42 CEST 2019


New items must always be added _before_ the 'history' cursor, so they
will always move it to the right.

The confusion came from an earlier implementation, where "history == 0"
was synonymous with "no history" (and it was not possible to consider
the whole array as history).

Fixes #22305
---
 src/playlist/randomizer.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/src/playlist/randomizer.c b/src/playlist/randomizer.c
index 1490caa9a9..1bbf14c55b 100644
--- a/src/playlist/randomizer.c
+++ b/src/playlist/randomizer.c
@@ -423,18 +423,13 @@ randomizer_Next(struct randomizer *r)
 bool
 randomizer_Add(struct randomizer *r, vlc_playlist_item_t *items[], size_t count)
 {
-    if (r->history)
-    {
-        if (!vlc_vector_insert_all(&r->items, r->history, items, count))
-            return false;
-        /* the insertion shifted history (and possibly next) */
-        if (r->next > r->history)
-            r->next += count;
-        r->history += count;
-        return true;
-    }
-
-    return vlc_vector_push_all(&r->items, items, count);
+    if (!vlc_vector_insert_all(&r->items, r->history, items, count))
+        return false;
+    /* the insertion shifted history (and possibly next) */
+    if (r->next > r->history)
+        r->next += count;
+    r->history += count;
+    return true;
 }
 
 static void
-- 
2.20.1



More information about the vlc-devel mailing list