diff mbox series

[FFmpeg-devel,01/39] avcodec/rl: Remove nonstatic storage of RL tables

Message ID 20201210111657.2276739-2-andreas.rheinhardt@gmail.com
State Accepted
Commit 1ead0c6388ba7f74ccb0c3e991a49600c92c877e
Headers show
Series Make mpegvideo encoders init-threadsafe
Related show

Checks

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

Commit Message

Andreas Rheinhardt Dec. 10, 2020, 11:16 a.m. UTC
ff_rl_free() was added in 324e50ee95929a9491b855c5e15451145bd5d1ec,
but never used; nonstatic storage was not used long before that.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
The test for whether a RLTable has already been initialized will be
removed once all callers are behind ff_thread_once() (same for
INIT_VLC_RL). This will happen soon.

 libavcodec/rl.c | 50 ++++++++-----------------------------------------
 libavcodec/rl.h | 11 +++--------
 2 files changed, 11 insertions(+), 50 deletions(-)

Comments

Anton Khirnov Dec. 30, 2020, 5:35 p.m. UTC | #1
Quoting Andreas Rheinhardt (2020-12-10 12:16:19)
> ff_rl_free() was added in 324e50ee95929a9491b855c5e15451145bd5d1ec,
> but never used; nonstatic storage was not used long before that.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---

Looks ok.
diff mbox series

Patch

diff --git a/libavcodec/rl.c b/libavcodec/rl.c
index 6eac306b88..c532b5bf56 100644
--- a/libavcodec/rl.c
+++ b/libavcodec/rl.c
@@ -25,27 +25,16 @@ 
 
 #include "rl.h"
 
-void ff_rl_free(RLTable *rl)
-{
-    int i;
-
-    for (i = 0; i < 2; i++) {
-        av_freep(&rl->max_run[i]);
-        av_freep(&rl->max_level[i]);
-        av_freep(&rl->index_run[i]);
-    }
-}
-
-av_cold int ff_rl_init(RLTable *rl,
-                       uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3])
+av_cold void ff_rl_init(RLTable *rl,
+                        uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3])
 {
     int8_t  max_level[MAX_RUN + 1], max_run[MAX_LEVEL + 1];
     uint8_t index_run[MAX_RUN + 1];
     int last, run, level, start, end, i;
 
-    /* If table is static, we can quit if rl->max_level[0] is not NULL */
-    if (static_store && rl->max_level[0])
-        return 0;
+    /* If rl->max_level[0] is set, this RLTable has already been initialized */
+    if (rl->max_level[0])
+        return;
 
     /* compute max_level[], max_run[] and index_run[] */
     for (last = 0; last < 2; last++) {
@@ -70,36 +59,13 @@  av_cold int ff_rl_init(RLTable *rl,
             if (run > max_run[level])
                 max_run[level] = run;
         }
-        if (static_store)
-            rl->max_level[last] = static_store[last];
-        else {
-            rl->max_level[last] = av_malloc(MAX_RUN + 1);
-            if (!rl->max_level[last])
-                goto fail;
-        }
+        rl->max_level[last] = static_store[last];
         memcpy(rl->max_level[last], max_level, MAX_RUN + 1);
-        if (static_store)
-            rl->max_run[last]   = static_store[last] + MAX_RUN + 1;
-        else {
-            rl->max_run[last]   = av_malloc(MAX_LEVEL + 1);
-            if (!rl->max_run[last])
-                goto fail;
-        }
+        rl->max_run[last]   = static_store[last] + MAX_RUN + 1;
         memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1);
-        if (static_store)
-            rl->index_run[last] = static_store[last] + MAX_RUN + MAX_LEVEL + 2;
-        else {
-            rl->index_run[last] = av_malloc(MAX_RUN + 1);
-            if (!rl->index_run[last])
-                goto fail;
-        }
+        rl->index_run[last] = static_store[last] + MAX_RUN + MAX_LEVEL + 2;
         memcpy(rl->index_run[last], index_run, MAX_RUN + 1);
     }
-    return 0;
-
-fail:
-    ff_rl_free(rl);
-    return AVERROR(ENOMEM);
 }
 
 av_cold void ff_rl_init_vlc(RLTable *rl, unsigned static_size)
diff --git a/libavcodec/rl.h b/libavcodec/rl.h
index 9a767bc5fd..a83debccf7 100644
--- a/libavcodec/rl.h
+++ b/libavcodec/rl.h
@@ -49,17 +49,12 @@  typedef struct RLTable {
 } RLTable;
 
 /**
- * @param static_store static uint8_t array[2][2*MAX_RUN + MAX_LEVEL + 3] which will hold
- *                     the level and run tables, if this is NULL av_malloc() will be used
+ * @param static_store static uint8_t array[2][2*MAX_RUN + MAX_LEVEL + 3]
+ *                     to hold the level and run tables.
  */
-int ff_rl_init(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3]);
+void ff_rl_init(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3]);
 void ff_rl_init_vlc(RLTable *rl, unsigned static_size);
 
-/**
- * Free the contents of a dynamically allocated table.
- */
-void ff_rl_free(RLTable *rl);
-
 #define INIT_VLC_RL(rl, static_size)\
 {\
     int q;\