From c12108cdaa7033645963ba61af8a0edfc0c1792c Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Wed, 9 Apr 2025 16:44:12 +0200 Subject: [PATCH] avcodec/hq_hqa: Don't zero in small chunks, don't zero twice Up until now, hq_decode_block() zeroed every block (of 128 bytes) before decoding a block; yet this is suboptimal for all modes, because all modes need to reset all the blocks they use anyway and so it should be done in one go for all blocks. For the alpha mode (where blocks need not be coded) all blocks are zeroed initially anyway, because decode_block() might not be doing it, so zeroing there again for the coded blocks is a waste. Signed-off-by: Andreas Rheinhardt --- libavcodec/hq_hqa.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libavcodec/hq_hqa.c b/libavcodec/hq_hqa.c index 48fc4896ee..5a7d8f12b6 100644 --- a/libavcodec/hq_hqa.c +++ b/libavcodec/hq_hqa.c @@ -78,8 +78,6 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64], const int32_t *q; int val, pos = 1; - memset(block, 0, 64 * sizeof(*block)); - if (!is_hqa) { block[0] = get_sbits(gb, 9) * 64; q = hq_quants[qsel][is_chroma][get_bits(gb, 2)]; @@ -109,6 +107,8 @@ static int hq_decode_mb(HQContext *c, AVFrame *pic, int qgroup, flag; int i, ret; + memset(c->block, 0, 8 * sizeof(c->block[0])); + qgroup = get_bits(gb, 4); flag = get_bits1(gb); @@ -197,8 +197,7 @@ static int hqa_decode_mb(HQContext *c, AVFrame *pic, int qgroup, if (get_bits_left(gb) < 1) return AVERROR_INVALIDDATA; - for (i = 0; i < 12; i++) - memset(c->block[i], 0, sizeof(*c->block)); + memset(c->block, 0, 12 * sizeof(c->block[0])); for (i = 0; i < 12; i++) c->block[i][0] = -128 * (1 << 6);