From 4d3d4c2842bf752c403a5a9e4207acb42463a12c Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Wed, 9 Apr 2025 16:44:12 +0200
Subject: [PATCH 03/10] 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 <andreas.rheinhardt@outlook.com>
---
 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..a16478b918 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, sizeof(c->block));
     for (i = 0; i < 12; i++)
         c->block[i][0] = -128 * (1 << 6);
 
-- 
2.45.2