diff mbox series

[FFmpeg-devel,12/21] avcodec/smacker: Remove redundant check when decoding header trees

Message ID 20200801134704.3647-4-andreas.rheinhardt@gmail.com
State Accepted
Commit 943a4581570728b4b1a2bf97e5601e24f3f80404
Headers show
Series [FFmpeg-devel,1/8] avcodec/smacker: Remove write-only and unused variables | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 1, 2020, 1:46 p.m. UTC
When length is zero for a leaf node (which happens iff the Huffman tree
consists of one leaf node only), prefix is also automatically zero.

Performance impact is negligible: For GCC 9 and the sample from #2425,
the time for one call to smka_decode_frame() decreased from 2053758 to
2053671 decicycles; for Clang 9 it went from 1523153 to 1521288.

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

Comments

Paul B Mahol Aug. 1, 2020, 2:17 p.m. UTC | #1
probably fine

On 8/1/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> When length is zero for a leaf node (which happens iff the Huffman tree
> consists of one leaf node only), prefix is also automatically zero.
>
> Performance impact is negligible: For GCC 9 and the sample from #2425,
> the time for one call to smka_decode_frame() decreased from 2053758 to
> 2053671 decicycles; for Clang 9 it went from 1523153 to 1521288.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/smacker.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
> index c249ce7514..991622eb0e 100644
> --- a/libavcodec/smacker.c
> +++ b/libavcodec/smacker.c
> @@ -105,13 +105,8 @@ static int smacker_decode_tree(GetBitContext *gb,
> HuffContext *hc, uint32_t pref
>              av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
>              return AVERROR_INVALIDDATA;
>          }
> -        if(length){
> -            hc->bits[hc->current] = prefix;
> -            hc->lengths[hc->current] = length;
> -        } else {
> -            hc->bits[hc->current] = 0;
> -            hc->lengths[hc->current] = 0;
> -        }
> +        hc->bits[hc->current]    = prefix;
> +        hc->lengths[hc->current] = length;
>          hc->values[hc->current] = get_bits(gb, 8);
>          hc->current++;
>          return 0;
> --
> 2.20.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/smacker.c b/libavcodec/smacker.c
index c249ce7514..991622eb0e 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -105,13 +105,8 @@  static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t pref
             av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
             return AVERROR_INVALIDDATA;
         }
-        if(length){
-            hc->bits[hc->current] = prefix;
-            hc->lengths[hc->current] = length;
-        } else {
-            hc->bits[hc->current] = 0;
-            hc->lengths[hc->current] = 0;
-        }
+        hc->bits[hc->current]    = prefix;
+        hc->lengths[hc->current] = length;
         hc->values[hc->current] = get_bits(gb, 8);
         hc->current++;
         return 0;