[FFmpeg-devel] [PATCH 2/3] avutil/mem: make ff_fast_malloc() internal to mem.c

James Almer jamrial at gmail.com
Sun May 23 17:54:32 EEST 2021


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavutil/mem.c          | 24 ++++++++++++++++++++++--
 libavutil/mem_internal.h | 18 ------------------
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/libavutil/mem.c b/libavutil/mem.c
index c12c24aa90..471b49f8e7 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -510,12 +510,32 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
     return ptr;
 }
 
+
+static inline void fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
+{
+    void *val;
+
+    memcpy(&val, ptr, sizeof(val));
+    if (min_size <= *size) {
+        av_assert0(val || !min_size);
+        return;
+    }
+    min_size = FFMAX(min_size + min_size / 16 + 32, min_size);
+    av_freep(ptr);
+    val = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size);
+    memcpy(ptr, &val, sizeof(val));
+    if (!val)
+        min_size = 0;
+    *size = min_size;
+    return;
+}
+
 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
 {
-    ff_fast_malloc(ptr, size, min_size, 0);
+    fast_malloc(ptr, size, min_size, 0);
 }
 
 void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
 {
-    ff_fast_malloc(ptr, size, min_size, 1);
+    fast_malloc(ptr, size, min_size, 1);
 }
diff --git a/libavutil/mem_internal.h b/libavutil/mem_internal.h
index ee2575c85f..ed846aac52 100644
--- a/libavutil/mem_internal.h
+++ b/libavutil/mem_internal.h
@@ -136,22 +136,4 @@
 #   define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,))
 #endif
 
-static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
-{
-    void *val;
-
-    memcpy(&val, ptr, sizeof(val));
-    if (min_size <= *size) {
-        av_assert0(val || !min_size);
-        return 0;
-    }
-    min_size = FFMAX(min_size + min_size / 16 + 32, min_size);
-    av_freep(ptr);
-    val = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size);
-    memcpy(ptr, &val, sizeof(val));
-    if (!val)
-        min_size = 0;
-    *size = min_size;
-    return 1;
-}
 #endif /* AVUTIL_MEM_INTERNAL_H */
-- 
2.31.1



More information about the ffmpeg-devel mailing list