[vlc-commits] subtitle demux: use qsort instead of bubblesort
Ilkka Ollakka
git at videolan.org
Sat Oct 3 17:11:58 CEST 2015
vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Sat Oct 3 13:16:57 2015 +0300| [70f2ac5f9020f7e86089dc487740153772ead39b] | committer: Ilkka Ollakka
subtitle demux: use qsort instead of bubblesort
Most likely no major speed difference with low amount of subtitles.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=70f2ac5f9020f7e86089dc487740153772ead39b
---
modules/demux/subtitle.c | 32 ++++++--------------------------
1 file changed, 6 insertions(+), 26 deletions(-)
diff --git a/modules/demux/subtitle.c b/modules/demux/subtitle.c
index 59b8e02..0afb9d1 100644
--- a/modules/demux/subtitle.c
+++ b/modules/demux/subtitle.c
@@ -758,40 +758,20 @@ static int Demux( demux_t *p_demux )
return 1;
}
+
+static int subtitle_cmp( const void *first, const void *second )
+{
+ return ((subtitle_t *)(first))->i_start - ((subtitle_t *)(second))->i_start;
+}
/*****************************************************************************
* Fix: fix time stamp and order of subtitle
*****************************************************************************/
static void Fix( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
- bool b_done;
/* *** fix order (to be sure...) *** */
- /* We suppose that there are near in order and this durty bubble sort
- * would not take too much time
- */
- do
- {
- b_done = true;
- for( int i_index = 1; i_index < p_sys->i_subtitles; i_index++ )
- {
- if( p_sys->subtitle[i_index].i_start <
- p_sys->subtitle[i_index - 1].i_start )
- {
- subtitle_t sub_xch;
- memcpy( &sub_xch,
- p_sys->subtitle + i_index - 1,
- sizeof( subtitle_t ) );
- memcpy( p_sys->subtitle + i_index - 1,
- p_sys->subtitle + i_index,
- sizeof( subtitle_t ) );
- memcpy( p_sys->subtitle + i_index,
- &sub_xch,
- sizeof( subtitle_t ) );
- b_done = false;
- }
- }
- } while( !b_done );
+ qsort( p_sys->subtitle, p_sys->i_subtitles, sizeof( p_sys->subtitle[0] ), subtitle_cmp);
}
static int TextLoad( text_t *txt, stream_t *s )
More information about the vlc-commits
mailing list