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

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


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Thu May 16 12:32:55 2019 +0200| [ea87e768e2965e8830ce36f2ee584b7d41e9bead] | committer: Jean-Baptiste Kempf

randomizer: fix history cursor on removal

randomizer_RemoveAt() did not manage the 'history' cursor correctly: it
explicitly tested "r->history == 0", which meant "no history" in
an earlier implementation, but not anymore.

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

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

 src/playlist/randomizer.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/src/playlist/randomizer.c b/src/playlist/randomizer.c
index 2da77b84fd..388cc02139 100644
--- a/src/playlist/randomizer.c
+++ b/src/playlist/randomizer.c
@@ -483,7 +483,7 @@ randomizer_RemoveAt(struct randomizer *r, size_t index)
      *    ordered            order irrelevant               ordered
      */
 
-    /* update next before may be updated */
+    /* update next before index may be updated */
     if (index < r->next)
         r->next--;
 
@@ -497,26 +497,20 @@ randomizer_RemoveAt(struct randomizer *r, size_t index)
         index = r->head; /* the new index to remove */
     }
 
-    if (!r->history || index < r->history)
+    if (index < r->history)
     {
-        size_t swap = (r->history + r->items.size - 1) % r->items.size;
-        r->items.data[index] = r->items.data[swap];
-        index = swap;
+        /* this part is unordered, no need to shift all items */
+        r->items.data[index] = r->items.data[r->history - 1];
+        index = r->history - 1;
+        r->history--;
     }
 
-    if (r->history)
+    if (index < r->items.size - 1)
     {
+        /* shift the ordered history part by one */
         memmove(&r->items.data[index],
                 &r->items.data[index + 1],
                 (r->items.size - index - 1) * sizeof(*r->items.data));
-
-        if (index < r->history)
-            r->history--;
-        else if (r->history == r->items.size)
-            r->history = 0;
-
-        if (r->next == r->items.size)
-            r->next = 0;
     }
 
     r->items.size--;



More information about the vlc-commits mailing list