[vlc-commits] playlist/sd: use linked list

Rémi Denis-Courmont git at videolan.org
Sun Jun 17 20:13:11 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 17 20:25:26 2018 +0300| [9beda09da3c9664b312cb17cc7759bf3f36a3036] | committer: Rémi Denis-Courmont

playlist/sd: use linked list

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

 src/playlist/engine.c             |  2 +-
 src/playlist/playlist_internal.h  |  5 +----
 src/playlist/services_discovery.c | 42 ++++++++++++++-------------------------
 3 files changed, 17 insertions(+), 32 deletions(-)

diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index 0a161a38c7..10c4cf03e6 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -199,7 +199,7 @@ playlist_t *playlist_Create( vlc_object_t *p_parent )
     p->input_tree = NULL;
     p->id_tree = NULL;
 
-    TAB_INIT( pl_priv(p_playlist)->i_sds, pl_priv(p_playlist)->pp_sds );
+    vlc_list_init(&p->sds);
 
     VariablesInit( p_playlist );
     vlc_mutex_init( &p->lock );
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index ae48c75e87..6432c6e083 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -40,8 +40,6 @@
 #include "art.h"
 #include "preparser.h"
 
-typedef struct vlc_sd_internal_t vlc_sd_internal_t;
-
 void playlist_ServicesDiscoveryKillAll( playlist_t *p_playlist );
 
 typedef struct playlist_private_t
@@ -53,8 +51,7 @@ typedef struct playlist_private_t
                            to playlist item mapping */
     void *id_tree; /**< Search tree for item ID to item mapping */
 
-    vlc_sd_internal_t   **pp_sds;
-    int                   i_sds;   /**< Number of service discovery modules */
+    struct vlc_list       sds;
     input_thread_t *      p_input;  /**< the input thread associated
                                      * with the current item */
     input_resource_t *   p_input_resource; /**< input resources */
diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c
index 3e68366ed2..e14682fc73 100644
--- a/src/playlist/services_discovery.c
+++ b/src/playlist/services_discovery.c
@@ -30,13 +30,14 @@
 #include <vlc_services_discovery.h>
 #include "playlist_internal.h"
 
-struct vlc_sd_internal_t
+typedef struct vlc_sd_internal_t
 {
     /* the playlist items for category and onelevel */
     playlist_item_t      *node;
     services_discovery_t *sd; /**< Loaded service discovery modules */
+    struct vlc_list       siblings;
     char name[];
-};
+} vlc_sd_internal_t;
 
  /* A new item has been added to a certain sd */
 static void playlist_sd_item_added(services_discovery_t *sd,
@@ -146,7 +147,7 @@ int playlist_ServicesDiscoveryAdd(playlist_t *playlist, const char *chain)
                                         &playlist->root, PLAYLIST_END,
                                         PLAYLIST_RO_FLAG);
 
-    TAB_APPEND(pl_priv(playlist)->i_sds, pl_priv(playlist)->pp_sds, sds);
+    vlc_list_append(&sds->siblings, &pl_priv(playlist)->sds);
     playlist_Unlock(playlist);
     return VLC_SUCCESS;
 }
@@ -171,20 +172,16 @@ static void playlist_ServicesDiscoveryInternalRemove(playlist_t *playlist,
 int playlist_ServicesDiscoveryRemove(playlist_t *playlist, const char *name)
 {
     playlist_private_t *priv = pl_priv(playlist);
-    vlc_sd_internal_t *sds = NULL;
+    vlc_sd_internal_t *sds = NULL, *entry;
 
     playlist_Lock(playlist);
-    for (int i = 0; i < priv->i_sds; i++)
-    {
-        vlc_sd_internal_t *entry = priv->pp_sds[i];
-
+    vlc_list_foreach(entry, &priv->sds, siblings)
         if (!strcmp(name, entry->name))
         {
-            TAB_ERASE(priv->i_sds, priv->pp_sds, i);
+            vlc_list_remove(&sds->siblings);
             sds = entry;
             break;
         }
-    }
     playlist_Unlock(playlist);
 
     if (sds == NULL)
@@ -201,19 +198,16 @@ bool playlist_IsServicesDiscoveryLoaded( playlist_t * playlist,
                                          const char *psz_name )
 {
     playlist_private_t *priv = pl_priv( playlist );
+    vlc_sd_internal_t *sds;
     bool found = false;
-    playlist_Lock(playlist);
-
-    for( int i = 0; i < priv->i_sds; i++ )
-    {
-        vlc_sd_internal_t *sds = priv->pp_sds[i];
 
+    playlist_Lock(playlist);
+    vlc_list_foreach(sds, &priv->sds, siblings)
         if (!strcmp(psz_name, sds->name))
         {
             found = true;
             break;
         }
-    }
     playlist_Unlock(playlist);
     return found;
 }
@@ -221,13 +215,11 @@ bool playlist_IsServicesDiscoveryLoaded( playlist_t * playlist,
 int playlist_ServicesDiscoveryControl( playlist_t *playlist, const char *psz_name, int i_control, ... )
 {
     playlist_private_t *priv = pl_priv( playlist );
+    vlc_sd_internal_t *sds;
     int i_ret = VLC_EGENERIC;
-    int i;
 
     playlist_Lock(playlist);
-    for( i = 0; i < priv->i_sds; i++ )
-    {
-        vlc_sd_internal_t *sds = priv->pp_sds[i];
+    vlc_list_foreach(sds, &priv->sds, siblings)
         if (!strcmp(psz_name, sds->name))
         {
             va_list args;
@@ -236,9 +228,6 @@ int playlist_ServicesDiscoveryControl( playlist_t *playlist, const char *psz_nam
             va_end( args );
             break;
         }
-    }
-
-    assert( i != priv->i_sds );
     playlist_Unlock(playlist);
 
     return i_ret;
@@ -247,9 +236,8 @@ int playlist_ServicesDiscoveryControl( playlist_t *playlist, const char *psz_nam
 void playlist_ServicesDiscoveryKillAll(playlist_t *playlist)
 {
     playlist_private_t *priv = pl_priv(playlist);
+    vlc_sd_internal_t *sds;
 
-    for (int i = 0; i < priv->i_sds; i++)
-        playlist_ServicesDiscoveryInternalRemove(playlist, priv->pp_sds[i]);
-
-    TAB_CLEAN(priv->i_sds, priv->pp_sds);
+    vlc_list_foreach(sds, &priv->sds, siblings)
+        playlist_ServicesDiscoveryInternalRemove(playlist, sds);
 }



More information about the vlc-commits mailing list