[vlc-devel] [PATCH 06/10] playlist/item: utilize TAB_FIND in ItemIndex

Filip Roséen filip at atch.se
Mon Oct 10 18:17:58 CEST 2016


Even though this results in more lines than the previous
implementation, it should be easier to read and reason about the
implementation using the already defined helper for finding entities
within a vlc TAB.
---
 src/playlist/item.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/playlist/item.c b/src/playlist/item.c
index e5ac372..d2b6272 100644
--- a/src/playlist/item.c
+++ b/src/playlist/item.c
@@ -653,9 +653,14 @@ playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
 
 static int ItemIndex ( playlist_item_t *p_item )
 {
-    for( int i = 0; i < p_item->p_parent->i_children; i++ )
-        if( p_item->p_parent->pp_children[i] == p_item ) return i;
-    return -1;
+    int idx;
+
+    TAB_FIND( p_item->p_parent->i_children,
+              p_item->p_parent->pp_children,
+              p_item,
+              idx );
+
+    return idx;
 }
 
 /**
-- 
2.10.0



More information about the vlc-devel mailing list