[vlc-commits] input: remove input_item_node_t.pf_compar

Rémi Denis-Courmont git at videolan.org
Mon Nov 21 20:35:15 CET 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Nov 21 21:17:37 2016 +0200| [9b1ac09c996c9502402738419d989da561abd4f9] | committer: Rémi Denis-Courmont

input: remove input_item_node_t.pf_compar

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

 include/vlc_input_item.h |  9 ---------
 src/input/access.c       | 48 +++++++++++++++++++++++++++++++++++++++---------
 src/input/item.c         | 46 ----------------------------------------------
 src/libvlccore.sym       |  1 -
 4 files changed, 39 insertions(+), 65 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 8e1184f..30afb02 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -163,15 +163,12 @@ struct input_item_slave
     char                psz_uri[];  /**< Slave mrl */
 };
 
-typedef int (*input_item_compar_cb)( input_item_t *, input_item_t * );
-
 struct input_item_node_t
 {
     input_item_t *         p_item;
     int                    i_children;
     input_item_node_t      **pp_children;
     input_item_node_t      *p_parent;
-    input_item_compar_cb   compar_cb;
 };
 
 VLC_API void input_item_CopyOptions( input_item_t *p_child, input_item_t *p_parent );
@@ -207,12 +204,6 @@ VLC_API input_item_node_t * input_item_node_AppendItem( input_item_node_t *p_nod
 VLC_API void input_item_node_AppendNode( input_item_node_t *p_parent, input_item_node_t *p_child );
 
 /**
- * Sort all p_item children of the node recursively.
- */
-VLC_API void input_item_node_Sort( input_item_node_t *p_node,
-                                   input_item_compar_cb compar_cb );
-
-/**
  * Delete a node created with input_item_node_Create() and all its children.
  */
 VLC_API void input_item_node_Delete( input_item_node_t *p_node );
diff --git a/src/input/access.c b/src/input/access.c
index 22d9582..6c48431 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -332,34 +332,64 @@ static int compar_type(input_item_t *p1, input_item_t *p2)
     return 0;
 }
 
-static int compar_collate(input_item_t *p1, input_item_t *p2)
+/* Some code duplication between comparison functions.
+ * GNU qsort_r() would be needed to solve this. */
+static int compar_collate(const void *a, const void *b)
 {
-    int i_ret = compar_type(p1, p2);
+    input_item_node_t *const *na = a, *const *nb = b;
+    input_item_t *ia = (*na)->p_item, *ib = (*nb)->p_item;
 
+    int i_ret = compar_type(ia, ib);
     if (i_ret != 0)
         return i_ret;
 
 #ifdef HAVE_STRCOLL
     /* The program's LOCAL defines if case is ignored */
-    return strcoll(p1->psz_name, p2->psz_name);
+    return strcoll(ia->psz_name, ib->psz_name);
 #else
-    return strcasecmp(p1->psz_name, p2->psz_name);
+    return strcasecmp(ia->psz_name, ib->psz_name);
 #endif
 }
 
-static int compar_version(input_item_t *p1, input_item_t *p2)
+static int compar_version(const void *a, const void *b)
 {
-    int i_ret = compar_type(p1, p2);
+    input_item_node_t *const *na = a, *const *nb = b;
+    input_item_t *ia = (*na)->p_item, *ib = (*nb)->p_item;
 
+    int i_ret = compar_type(ia, ib);
     if (i_ret != 0)
         return i_ret;
 
-    return strverscmp(p1->psz_name, p2->psz_name);
+    return strverscmp(ia->psz_name, ib->psz_name);
+}
+
+static void fsdir_sort_sub(input_item_node_t *p_node,
+                           int (*compar)(const void *, const void *))
+{
+    if (p_node->i_children <= 0)
+        return;
+
+    /* Lock first all children. This avoids to lock/unlock them from each
+     * compar callback call */
+    for (int i = 0; i < p_node->i_children; i++)
+        vlc_mutex_lock(&p_node->pp_children[i]->p_item->lock);
+
+    /* Sort current node */
+    qsort(p_node->pp_children, p_node->i_children,
+          sizeof(input_item_node_t *), compar);
+
+    /* Unlock all children */
+    for (int i = 0; i < p_node->i_children; i++)
+        vlc_mutex_unlock(&p_node->pp_children[i]->p_item->lock);
+
+    /* Sort all children */
+    for (int i = 0; i < p_node->i_children; i++)
+        fsdir_sort_sub(p_node->pp_children[i], compar);
 }
 
 static void fsdir_sort(struct access_fsdir *p_fsdir)
 {
-    input_item_compar_cb pf_compar = NULL;
+    int (*pf_compar)(const void *, const void *) = NULL;
 
     if (p_fsdir->psz_sort != NULL)
     {
@@ -369,7 +399,7 @@ static void fsdir_sort(struct access_fsdir *p_fsdir)
             pf_compar = compar_collate;
 
         if (pf_compar != NULL)
-            input_item_node_Sort(p_fsdir->p_node, pf_compar);
+            fsdir_sort_sub(p_fsdir->p_node, pf_compar);
     }
 }
 
diff --git a/src/input/item.c b/src/input/item.c
index 37cc658..a30188a 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -1276,52 +1276,6 @@ void input_item_node_AppendNode( input_item_node_t *p_parent, input_item_node_t
     p_child->p_parent = p_parent;
 }
 
-static int compar_node( const void *p1, const void *p2 )
-{
-    input_item_node_t *p_node1 = *((input_item_node_t **) p1);
-    input_item_node_t *p_node2 = *((input_item_node_t **) p2);
-
-    assert( p_node1->p_parent && p_node1->p_parent == p_node2->p_parent &&
-            p_node1->p_parent->compar_cb );
-
-    input_item_compar_cb compar_cb = p_node1->p_parent->compar_cb;
-    return compar_cb( p_node1->p_item, p_node2->p_item );
-}
-
-static void sort_subitems( input_item_node_t *p_node,
-                           input_item_compar_cb compar_cb )
-{
-    if( p_node->i_children <= 0 || !compar_cb )
-        return;
-
-    p_node->compar_cb = compar_cb;
-
-    /* Lock first all children. This avoids to lock/unlock them from each
-     * compar callback call */
-    for( int i = 0; i < p_node->i_children; i++ )
-        vlc_mutex_lock( &p_node->pp_children[i]->p_item->lock );
-
-    /* Sort current node */
-    qsort( p_node->pp_children, p_node->i_children,
-           sizeof(input_item_node_t *), compar_node );
-
-    /* Unlock all children */
-    for( int i = 0; i < p_node->i_children; i++ )
-        vlc_mutex_unlock( &p_node->pp_children[i]->p_item->lock );
-
-    p_node->compar_cb = NULL;
-
-    /* Sort all children */
-    for( int i = 0; i < p_node->i_children; i++ )
-        sort_subitems( p_node->pp_children[i], compar_cb );
-}
-
-void input_item_node_Sort( input_item_node_t *p_node,
-                           input_item_compar_cb compar_cb )
-{
-    sort_subitems( p_node, compar_cb );
-}
-
 void input_item_node_PostAndDelete( input_item_node_t *p_root )
 {
     post_subitems( p_root );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index d322841..d967523 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -202,7 +202,6 @@ input_item_node_AppendNode
 input_item_node_Create
 input_item_node_Delete
 input_item_node_PostAndDelete
-input_item_node_Sort
 input_item_PostSubItem
 input_item_ReplaceInfos
 input_item_SetDuration



More information about the vlc-commits mailing list