[vlc-commits] randomizer: fix history cursor on insertion

Romain Vimont git at videolan.org
Wed May 22 21:44:27 CEST 2019


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Wed May 15 16:22:08 2019 +0200| [ceebb7128ad9e00bf631be1c4f2e2defdd57ef8c] | committer: Jean-Baptiste Kempf

randomizer: fix history cursor on insertion

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

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ceebb7128ad9e00bf631be1c4f2e2defdd57ef8c
---

 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



More information about the vlc-commits mailing list