playlist/item-ext.c: more elegant binary search in playlist_ItemGetById()

parent 6697b0d9
...@@ -464,15 +464,15 @@ playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id ) ...@@ -464,15 +464,15 @@ playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id )
i_bottom = 0; i_top = p_playlist->i_all_size; i_bottom = 0; i_top = p_playlist->i_all_size;
i = i_top / 2; i = i_top / 2;
while( p_playlist->pp_all_items[i]->input.i_id != i_id && while( p_playlist->pp_all_items[i]->input.i_id != i_id &&
i_top > i_bottom + 1 ) i_top > i_bottom )
{ {
if( p_playlist->pp_all_items[i]->input.i_id < i_id ) if( p_playlist->pp_all_items[i]->input.i_id < i_id )
{ {
i_bottom = i; i_bottom = i + 1;
} }
else else
{ {
i_top = i; i_top = i - 1;
} }
i = i_bottom + ( i_top - i_bottom ) / 2; i = i_bottom + ( i_top - i_bottom ) / 2;
} }
...@@ -480,10 +480,6 @@ playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id ) ...@@ -480,10 +480,6 @@ playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id )
{ {
return p_playlist->pp_all_items[i]; return p_playlist->pp_all_items[i];
} }
else if( p_playlist->pp_all_items[i_top]->input.i_id == i_id )
{
return p_playlist->pp_all_items[i_top];
}
return NULL; return NULL;
} }
......
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