[vlc-commits] media tree: clear children on subtree changed

Romain Vimont git at videolan.org
Fri Feb 8 16:23:46 CET 2019


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Fri Feb  8 14:35:00 2019 +0100| [011d187d3133814f1b8f968fc149c593bcfee9f7] | committer: Hugo Beauzée-Luyssen

media tree: clear children on subtree changed

On subitems changed, the old subitems (if any) must be removed.

Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

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

 src/media_source/media_tree.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/media_source/media_tree.c b/src/media_source/media_tree.c
index 6dd7055bcc..4c91b7eaf7 100644
--- a/src/media_source/media_tree.c
+++ b/src/media_source/media_tree.c
@@ -135,6 +135,17 @@ vlc_media_tree_AddSubtree(input_item_node_t *to, input_item_node_t *from)
 }
 
 static void
+vlc_media_tree_ClearChildren(input_item_node_t *root)
+{
+    for (int i = 0; i < root->i_children; ++i)
+        input_item_node_Delete(root->pp_children[i]);
+
+    free(root->pp_children);
+    root->pp_children = NULL;
+    root->i_children = 0;
+}
+
+static void
 media_subtree_changed(input_item_t *media, input_item_node_t *node,
                       void *userdata)
 {
@@ -151,19 +162,16 @@ media_subtree_changed(input_item_t *media, input_item_node_t *node,
         return;
     }
 
+    vlc_media_tree_ClearChildren(subtree_root);
     vlc_media_tree_AddSubtree(subtree_root, node);
     vlc_media_tree_Notify(tree, on_children_reset, subtree_root);
     vlc_media_tree_Unlock(tree);
 }
 
-static void
+static inline void
 vlc_media_tree_DestroyRootNode(vlc_media_tree_t *tree)
 {
-    input_item_node_t *root = &tree->root;
-    for (int i = 0; i < root->i_children; ++i)
-        input_item_node_Delete(root->pp_children[i]);
-
-    free(root->pp_children);
+    vlc_media_tree_ClearChildren(&tree->root);
 }
 
 static void



More information about the vlc-commits mailing list