Commit 9b1ac09c authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

input: remove input_item_node_t.pf_compar

parent 4860e4e3
......@@ -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 );
......@@ -206,12 +203,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.
*/
......
......@@ -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);
}
}
......
......@@ -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 );
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment