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

playlist: allocate the root item statically

This allocates space for the root playlist item directly inside the
playlist structure. Creation of that item required a special case
anyway as it was the only item without a parent.

As a consequence, one unhandled error case is removed.
parent d92ba5e8
......@@ -158,9 +158,9 @@ struct playlist_t
int i_current_index; /**< Index in current array */
/* Predefined items */
playlist_item_t * p_root;
playlist_item_t * p_playing;
playlist_item_t * p_media_library;
playlist_item_t root;
playlist_item_t *p_playing;
playlist_item_t *p_media_library;
};
/* A bit of macro magic to generate an enum out of the following list,
......
......@@ -1323,14 +1323,14 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
else if( !strcmp( psz_cmd, "playlist" ) )
{
msg_rc( "+----[ Playlist ]" );
print_playlist( p_intf, p_playlist->p_root, 0 );
print_playlist( p_intf, &p_playlist->root, 0 );
msg_rc( "+----[ End of playlist ]" );
}
else if( !strcmp( psz_cmd, "sort" ))
{
PL_LOCK;
playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root,
playlist_RecursiveNodeSort( p_playlist, &p_playlist->root,
SORT_ARTIST, ORDER_NORMAL );
PL_UNLOCK;
}
......
......@@ -1145,7 +1145,7 @@ static const float f_min_window_height = 307.;
}
} else {
PL_LOCK;
playlist_item_t *pl_item = playlist_ChildSearchName(p_playlist->p_root, [[item untranslatedTitle] UTF8String]);
playlist_item_t *pl_item = playlist_ChildSearchName(&p_playlist->root, [[item untranslatedTitle] UTF8String]);
if (pl_item != NULL)
[[[[VLCMain sharedInstance] playlist] model] changeRootItem:pl_item];
......
......@@ -416,7 +416,7 @@ static void PlaylistRebuild(intf_thread_t *intf)
playlist_t *p_playlist = pl_Get(intf);
PlaylistDestroy(sys);
PlaylistAddNode(sys, p_playlist->p_root, "");
PlaylistAddNode(sys, &p_playlist->root, "");
}
static int ItemChanged(vlc_object_t *p_this, const char *variable,
......@@ -1341,7 +1341,7 @@ static bool HandlePlaylistKey(intf_thread_t *intf, int key)
case 'o':
case 'O':
playlist_Lock(p_playlist);
playlist_RecursiveNodeSort(p_playlist, p_playlist->p_root,
playlist_RecursiveNodeSort(p_playlist, &p_playlist->root,
SORT_TITLE_NODES_FIRST,
(key == 'o')? ORDER_NORMAL : ORDER_REVERSE);
sys->need_update = true;
......
......@@ -390,7 +390,7 @@ void PLSelector::setSource( QTreeWidgetItem *item )
{
/* Find the right item for the SD */
/* FIXME: searching by name - what could possibly go wrong? */
pl_item = playlist_ChildSearchName( THEPL->p_root,
pl_item = playlist_ChildSearchName( &(THEPL->root),
vlc_gettext(qtu(item->data(0, LONGNAME_ROLE).toString())) );
/* Podcasts */
......
......@@ -378,7 +378,7 @@ void MessagesDialog::updatePLTree()
{
vlc_playlist_locker pl_lock ( THEPL );
pldebugTree->addTopLevelItem( PLWalk( p_playlist->p_root ) );
pldebugTree->addTopLevelItem( PLWalk( &p_playlist->root ) );
}
pldebugTree->expandAll();
......
......@@ -38,7 +38,7 @@ void CmdPlaytreeSort::execute()
/// \todo Choose the correct view
playlist_t *p_playlist = getPL();
PL_LOCK;
playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root,
playlist_RecursiveNodeSort( p_playlist, &p_playlist->root,
SORT_TITLE, ORDER_NORMAL );
PL_UNLOCK;
......
......@@ -256,9 +256,9 @@ void Playtree::buildTree()
clear();
playlist_Lock( m_pPlaylist );
for( int i = 0; i < m_pPlaylist->p_root->i_children; i++ )
for( int i = 0; i < m_pPlaylist->root.i_children; i++ )
{
buildNode( m_pPlaylist->p_root->pp_children[i], *this );
buildNode( m_pPlaylist->root.pp_children[i], *this );
}
playlist_Unlock( m_pPlaylist );
......
......@@ -296,11 +296,11 @@ static int vlclua_playlist_get( lua_State *L )
|| !strcasecmp( psz_what, "media library" ) )
p_item = p_playlist->p_media_library;
else if( !strcasecmp( psz_what, "root" ) )
p_item = p_playlist->p_root;
p_item = &p_playlist->root;
else
{
/* currently, psz_what must be SD module's longname! */
p_item = playlist_ChildSearchName( p_playlist->p_root, psz_what );
p_item = playlist_ChildSearchName( &p_playlist->root, psz_what );
if( !p_item )
{
......@@ -311,7 +311,7 @@ static int vlclua_playlist_get( lua_State *L )
}
else
{
p_item = p_playlist->p_root;
p_item = &p_playlist->root;
}
push_playlist_item( L, p_item );
PL_UNLOCK;
......@@ -323,8 +323,8 @@ static int vlclua_playlist_search( lua_State *L )
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
const char *psz_string = luaL_optstring( L, 1, "" );
PL_LOCK;
playlist_LiveSearchUpdate( p_playlist, p_playlist->p_root, psz_string, true );
push_playlist_item( L, p_playlist->p_root );
playlist_LiveSearchUpdate( p_playlist, &p_playlist->root, psz_string, true );
push_playlist_item( L, &p_playlist->root );
PL_UNLOCK;
return 1;
}
......
......@@ -233,24 +233,31 @@ playlist_t *playlist_Create( vlc_object_t *p_parent )
pl_priv(p_playlist)->b_tree = var_InheritBool( p_parent, "playlist-tree" );
pl_priv(p_playlist)->b_preparse = var_InheritBool( p_parent, "auto-preparse" );
p_playlist->root.p_input = NULL;
p_playlist->root.pp_children = NULL;
p_playlist->root.i_children = 0;
p_playlist->root.i_nb_played = 0;
p_playlist->root.i_id = 0;
p_playlist->root.i_flags = 0;
/* Create the root, playing items and meida library nodes */
playlist_item_t *root, *playing, *ml;
playlist_item_t *playing, *ml;
PL_LOCK;
root = playlist_NodeCreate( p_playlist, NULL, NULL, PLAYLIST_END, 0 );
playing = playlist_NodeCreate( p_playlist, _( "Playlist" ), root,
PLAYLIST_END, PLAYLIST_RO_FLAG | PLAYLIST_NO_INHERIT_FLAG );
playing = playlist_NodeCreate( p_playlist, _( "Playlist" ),
&p_playlist->root, PLAYLIST_END,
PLAYLIST_RO_FLAG|PLAYLIST_NO_INHERIT_FLAG );
if( var_InheritBool( p_parent, "media-library") )
ml = playlist_NodeCreate( p_playlist, _( "Media Library" ), root,
PLAYLIST_END, PLAYLIST_RO_FLAG | PLAYLIST_NO_INHERIT_FLAG );
ml = playlist_NodeCreate( p_playlist, _( "Media Library" ),
&p_playlist->root, PLAYLIST_END,
PLAYLIST_RO_FLAG|PLAYLIST_NO_INHERIT_FLAG );
else
ml = NULL;
PL_UNLOCK;
if( unlikely(root == NULL || playing == NULL) )
if( unlikely(playing == NULL) )
abort();
p_playlist->p_root = root;
p_playlist->p_playing = playing;
p_playlist->p_media_library = ml;
......@@ -333,7 +340,10 @@ void playlist_Destroy( playlist_t *p_playlist )
ARRAY_RESET( p_playlist->current );
/* Remove all remaining items */
playlist_NodeDelete( p_playlist, p_playlist->p_root, true );
if( p_playlist->p_media_library != NULL )
playlist_NodeDelete( p_playlist, p_playlist->p_media_library, true );
playlist_NodeDelete( p_playlist, p_playlist->p_playing, true );
assert( p_playlist->root.i_children <= 0 );
PL_UNLOCK;
vlc_cond_destroy( &p_sys->signal );
......
......@@ -54,7 +54,7 @@ static void playlist_sd_item_added(services_discovery_t *sd,
playlist_Lock(playlist);
if (sds->node == NULL)
sds->node = playlist_NodeCreate(playlist, longname, playlist->p_root,
sds->node = playlist_NodeCreate(playlist, longname, &playlist->root,
PLAYLIST_END,
PLAYLIST_RO_FLAG|PLAYLIST_SKIP_FLAG);
......@@ -137,7 +137,7 @@ int playlist_ServicesDiscoveryAdd(playlist_t *playlist, const char *chain)
* has not discovered any item. */
if (sds->node == NULL && sds->sd->description != NULL)
sds->node = playlist_NodeCreate(playlist, sds->sd->description,
playlist->p_root, PLAYLIST_END,
&playlist->root, PLAYLIST_END,
PLAYLIST_RO_FLAG|PLAYLIST_SKIP_FLAG);
TAB_APPEND(pl_priv(playlist)->i_sds, pl_priv(playlist)->pp_sds, sds);
......
......@@ -75,8 +75,7 @@ playlist_item_t * playlist_NodeCreate( playlist_t *p_playlist,
if( p_item == NULL ) return NULL;
if( p_parent != NULL )
playlist_NodeInsert( p_parent, p_item, i_pos );
playlist_NodeInsert( p_parent, p_item, i_pos );
playlist_SendAddNotify( p_playlist, p_item );
p_item->i_flags |= i_flags;
......
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