[FFmpeg-devel] [PATCH 2/4] avcodec/get_bits: Avoid 2nd bitstream read in GET_VLC() if bits are known at build and small

Michael Niedermayer michael at niedermayer.cc
Tue Oct 24 18:04:41 EEST 2023


Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 libavcodec/get_bits.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index cfcf97c021c..86cea00494a 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -581,8 +581,12 @@ static inline const uint8_t *align_get_bits(GetBitContext *s)
         n     = table[index].len;                               \
                                                                 \
         if (max_depth > 1 && n < 0) {                           \
-            LAST_SKIP_BITS(name, gb, bits);                     \
-            UPDATE_CACHE(name, gb);                             \
+            if (av_builtin_constant_p(bits <= MIN_CACHE_BITS/2) && bits <= MIN_CACHE_BITS/2) { \
+                SKIP_BITS(name, gb, bits);                      \
+            } else {                                            \
+                LAST_SKIP_BITS(name, gb, bits);                 \
+                UPDATE_CACHE(name, gb);                         \
+            }                                                   \
                                                                 \
             nb_bits = -n;                                       \
                                                                 \
-- 
2.17.1



More information about the ffmpeg-devel mailing list