diff mbox series

[FFmpeg-devel,3/6] avcodec/huffyuv(dec|enc): Use union for temp/temp16

Message ID GV1P250MB0737F9AF8789DE1ADCD4232A8F3C2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit cf96c0295ea9c8f58617408ed68dbb1cba8d1682
Headers show
Series [FFmpeg-devel,1/6] avcodec/huffyuvdec: Don't zero unnecessarily | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt April 4, 2024, 5:02 a.m. UTC
These pointers already point to the same buffers, so using
a union is possible and avoids the overhead of syncing the
pointers (and saves some memory).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/huffyuvdec.c | 11 +++++------
 libavcodec/huffyuvenc.c | 11 +++++------
 2 files changed, 10 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
index e390380867..12ecfcb933 100644
--- a/libavcodec/huffyuvdec.c
+++ b/libavcodec/huffyuvdec.c
@@ -70,8 +70,10 @@  typedef struct HYuvDecContext {
     int context;
     int last_slice_end;
 
-    uint8_t *temp[3];
-    uint16_t *temp16[3];                    ///< identical to temp but 16bit type
+    union {
+        uint8_t  *temp[3];
+        uint16_t *temp16[3];
+    };
     uint8_t len[4][MAX_VLC_N];
     uint32_t bits[4][MAX_VLC_N];
     uint32_t pix_bgr_map[1<<VLC_BITS];
@@ -323,10 +325,8 @@  static av_cold int decode_end(AVCodecContext *avctx)
     HYuvDecContext *s = avctx->priv_data;
     int i;
 
-    for (int i = 0; i < 3; i++) {
+    for (int i = 0; i < 3; i++)
         av_freep(&s->temp[i]);
-        s->temp16[i] = NULL;
-    }
 
     av_freep(&s->bitstream_buffer);
 
@@ -607,7 +607,6 @@  static av_cold int decode_init(AVCodecContext *avctx)
         s->temp[i] = av_malloc(4 * avctx->width + 16);
         if (!s->temp[i])
             return AVERROR(ENOMEM);
-        s->temp16[i] = (uint16_t*)s->temp[i];
     }
 
     return 0;
diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c
index 8329666fc0..4f709143a2 100644
--- a/libavcodec/huffyuvenc.c
+++ b/libavcodec/huffyuvenc.c
@@ -65,8 +65,10 @@  typedef struct HYuvEncContext {
     int context;
     int picture_number;
 
-    uint8_t *temp[3];
-    uint16_t *temp16[3];                    ///< identical to temp but 16bit type
+    union {
+        uint8_t  *temp[3];
+        uint16_t *temp16[3];
+    };
     uint64_t stats[4][MAX_VLC_N];
     uint8_t len[4][MAX_VLC_N];
     uint32_t bits[4][MAX_VLC_N];
@@ -436,7 +438,6 @@  static av_cold int encode_init(AVCodecContext *avctx)
         s->temp[i] = av_malloc(4 * avctx->width + 16);
         if (!s->temp[i])
             return AVERROR(ENOMEM);
-        s->temp16[i] = (uint16_t*)s->temp[i];
     }
 
     return 0;
@@ -1040,10 +1041,8 @@  static av_cold int encode_end(AVCodecContext *avctx)
 
     av_freep(&avctx->stats_out);
 
-    for (int i = 0; i < 3; i++) {
+    for (int i = 0; i < 3; i++)
         av_freep(&s->temp[i]);
-        s->temp16[i] = NULL;
-    }
 
     return 0;
 }