[FFmpeg-devel] [PATCH 2/7] avcodec/bonk: Simplify read_uint_max()
Michael Niedermayer
michael at niedermayer.cc
Thu Nov 10 21:42:08 EET 2022
On Sun, Nov 06, 2022 at 07:30:24PM +0100, Paul B Mahol wrote:
> On 11/6/22, Michael Niedermayer <michael at niedermayer.cc> wrote:
> > The max == 0 case can be removed too but i left it as 50% of the cases use
> > it
> >
> > Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> > ---
> > libavcodec/bonk.c | 11 ++---------
> > 1 file changed, 2 insertions(+), 9 deletions(-)
> >
> > diff --git a/libavcodec/bonk.c b/libavcodec/bonk.c
> > index 9e8892e4db..04ea4def2f 100644
> > --- a/libavcodec/bonk.c
> > +++ b/libavcodec/bonk.c
> > @@ -132,7 +132,6 @@ static av_cold int bonk_init(AVCodecContext *avctx)
> > static unsigned read_uint_max(BonkContext *s, uint32_t max)
> > {
> > unsigned value = 0;
> > - int i, bits;
> >
> > if (max == 0)
> > return 0;
> > @@ -140,15 +139,9 @@ static unsigned read_uint_max(BonkContext *s, uint32_t
> > max)
> > if (max >> 31)
> > return 32;
> >
> > - bits = 32 - ff_clz(max);
> > -
> > - for (i = 0; i < bits - 1; i++)
> > - if (get_bits1(&s->gb))
> > - value += 1 << i;
> > -
> > - if ((value | (1 << (bits - 1))) <= max)
> > + for (unsigned i = 1; i <= max - value; i+=i)
> > if (get_bits1(&s->gb))
> > - value += 1 << (bits - 1);
> > + value += i;
> >
> > return value;
> > }
> > --
> > 2.17.1
> >
>
> probably ok.
will apply
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Dictatorship: All citizens are under surveillance, all their steps and
actions recorded, for the politicians to enforce control.
Democracy: All politicians are under surveillance, all their steps and
actions recorded, for the citizens to enforce control.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20221110/5be853b0/attachment.sig>
More information about the ffmpeg-devel
mailing list