[FFmpeg-devel] [PATCH] all: replace qsort with AV_QSORT

Clément Bœsch u at pkh.me
Sun Oct 18 17:03:03 CEST 2015


On Sun, Oct 18, 2015 at 10:47:52AM -0400, Ganesh Ajjanagadde wrote:
[...]
> diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
> index bb89766..16ab245 100644
> --- a/libavformat/subtitles.c
> +++ b/libavformat/subtitles.c
> @@ -23,6 +23,7 @@
>  #include "avio_internal.h"
>  #include "libavutil/avassert.h"
>  #include "libavutil/avstring.h"
> +#include "libavutil/qsort.h"
>  
>  void ff_text_init_avio(void *s, FFTextReader *r, AVIOContext *pb)
>  {
> @@ -197,9 +198,12 @@ void ff_subtitles_queue_finalize(void *log_ctx, FFDemuxSubtitlesQueue *q)
>  {
>      int i;
>  
> -    qsort(q->subs, q->nb_subs, sizeof(*q->subs),
> -          q->sort == SUB_SORT_TS_POS ? cmp_pkt_sub_ts_pos
> -                                     : cmp_pkt_sub_pos_ts);
> +    if (q->sort == SUB_SORT_TS_POS) {
> +        AV_QSORT(q->subs, q->nb_subs, AVPacket, cmp_pkt_sub_ts_pos);
> +    }
> +    else
> +        AV_QSORT(q->subs, q->nb_subs, AVPacket, cmp_pkt_sub_pos_ts);
> +

Weird style.

BTW, AV_QSORT() Macro should be replaced with a do { ... } while (0) form
to make this kind of code safer.

Also note that using these macro has an impact on final binary size which
might not be worth the trouble in various cases.

[...]

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151018/33b8534d/attachment.sig>


More information about the ffmpeg-devel mailing list