From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 22A9240CAE for ; Sun, 6 Nov 2022 12:34:49 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D0F8C68B663; Sun, 6 Nov 2022 14:34:41 +0200 (EET) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 655EB68B612 for ; Sun, 6 Nov 2022 14:34:35 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 578C1C0005 for ; Sun, 6 Nov 2022 12:34:34 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 6 Nov 2022 13:34:25 +0100 Message-Id: <20221106123430.1668-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221106123430.1668-1-michael@niedermayer.cc> References: <20221106123430.1668-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 2/7] avcodec/bonk: Simplify read_uint_max() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: The max == 0 case can be removed too but i left it as 50% of the cases use it Signed-off-by: Michael Niedermayer --- 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 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".