diff mbox series

[FFmpeg-devel,1/2] avcodec/sheervideo: Improve creating VLC tables

Message ID 20201010045704.759353-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 1bff2f3d929b7e1229b9a125e3cf938ece1665cc
Headers show
Series [FFmpeg-devel,1/2] avcodec/sheervideo: Improve creating VLC tables | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Oct. 10, 2020, 4:57 a.m. UTC
Don't needlessly copy an array around; don't create a table with
default symbols; and use smaller types to save stack space: The longest
code here is 16 bits, so one can store the codes in this type.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/sheervideo.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

Comments

Paul B Mahol Oct. 10, 2020, 10:21 a.m. UTC | #1
On Sat, Oct 10, 2020 at 06:57:03AM +0200, Andreas Rheinhardt wrote:
> Don't needlessly copy an array around; don't create a table with
> default symbols; and use smaller types to save stack space: The longest
> code here is 16 bits, so one can store the codes in this type.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/sheervideo.c | 19 +++++++------------
>  1 file changed, 7 insertions(+), 12 deletions(-)
> 

probably fine

> diff --git a/libavcodec/sheervideo.c b/libavcodec/sheervideo.c
> index ba9aecbb11..3f9b299a1e 100644
> --- a/libavcodec/sheervideo.c
> +++ b/libavcodec/sheervideo.c
> @@ -1782,25 +1782,20 @@ static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
>  
>  static int build_vlc(VLC *vlc, const uint8_t *len, int count)
>  {
> -    uint32_t codes[1024];
> -    uint8_t bits[1024];
> -    uint16_t syms[1024];
> -    uint64_t index;
> +    uint16_t codes[1024];
> +    unsigned index;
>      int i;
>  
>      index = 0;
>      for (i = 0; i < count; i++) {
> -        codes[i]  = index >> (32 - len[i]);
> -        bits[i] = len[i];
> -        syms[i]  = i;
> -        index += 1ULL << (32 - len[i]);
> +        codes[i] = index >> (32 - len[i]);
> +        index   += 1U    << (32 - len[i]);
>      }
>  
>      ff_free_vlc(vlc);
> -    return ff_init_vlc_sparse(vlc, 12, count,
> -                              bits,  sizeof(*bits),  sizeof(*bits),
> -                              codes, sizeof(*codes), sizeof(*codes),
> -                              syms,  sizeof(*syms),  sizeof(*syms), 0);
> +    return init_vlc(vlc, 12, count,
> +                    len,   sizeof(*len),   sizeof(*len),
> +                    codes, sizeof(*codes), sizeof(*codes), 0);
>  }
>  
>  static int decode_frame(AVCodecContext *avctx,
> -- 
> 2.25.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".
diff mbox series

Patch

diff --git a/libavcodec/sheervideo.c b/libavcodec/sheervideo.c
index ba9aecbb11..3f9b299a1e 100644
--- a/libavcodec/sheervideo.c
+++ b/libavcodec/sheervideo.c
@@ -1782,25 +1782,20 @@  static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
 
 static int build_vlc(VLC *vlc, const uint8_t *len, int count)
 {
-    uint32_t codes[1024];
-    uint8_t bits[1024];
-    uint16_t syms[1024];
-    uint64_t index;
+    uint16_t codes[1024];
+    unsigned index;
     int i;
 
     index = 0;
     for (i = 0; i < count; i++) {
-        codes[i]  = index >> (32 - len[i]);
-        bits[i] = len[i];
-        syms[i]  = i;
-        index += 1ULL << (32 - len[i]);
+        codes[i] = index >> (32 - len[i]);
+        index   += 1U    << (32 - len[i]);
     }
 
     ff_free_vlc(vlc);
-    return ff_init_vlc_sparse(vlc, 12, count,
-                              bits,  sizeof(*bits),  sizeof(*bits),
-                              codes, sizeof(*codes), sizeof(*codes),
-                              syms,  sizeof(*syms),  sizeof(*syms), 0);
+    return init_vlc(vlc, 12, count,
+                    len,   sizeof(*len),   sizeof(*len),
+                    codes, sizeof(*codes), sizeof(*codes), 0);
 }
 
 static int decode_frame(AVCodecContext *avctx,