[FFmpeg-devel] [PATCH v2] avfilter/formats: optimize ff_all_formats
Michael Niedermayer
michael at niedermayer.cc
Mon Dec 23 22:32:35 EET 2019
On Mon, Dec 23, 2019 at 04:11:53PM +0100, Nicolas George wrote:
> Tomas Härdin (12019-12-09):
> > As far as I can tell this is OK, and it passes FATE. But it just looks
> > very very wrong. Why does this function even exist if all it
> > effectively does is return the integers from 0..count-1?
>
> For some time, there were gaps in the list of pixel formats, the task of
> this function was precisely there to avoid the gaps and keep only the
> actual pixel formats.
>
> I am not sure about this change. It is technically valid, but it may
> cause problems later.
>
> There is an intermediate solution: keep the loop, but allocate only
> once (simplified):
>
> while ((desc = ...))
> count++;
> ret->formats = av_malloc_array(count, sizeof(*ret->formats));
> count = 0;
> while ((desc = ...))
> ret->formats[count] = ...;
>
> What do other developers think about it, with these explanations?
The count once then allocate feels more robust than assuming on !gaps
Thanks
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20191223/380478a1/attachment.sig>
More information about the ffmpeg-devel
mailing list