aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/mem.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2021-05-23 11:24:17 -0300
committerJames Almer <jamrial@gmail.com>2021-05-27 10:29:52 -0300
commit786be70e28fe739b8e49893fa13ae4652a68d1ea (patch)
tree236ff12fb9f9ebaa3d93064bf8f4d1d713b1e7f7 /libavutil/mem.c
parente44cb7363fed11b638f1cfc798d942bcf1e4db50 (diff)
downloadffmpeg-786be70e28fe739b8e49893fa13ae4652a68d1ea.tar.gz
avutil/mem: make ff_fast_malloc() internal to mem.c
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavutil/mem.c')
-rw-r--r--libavutil/mem.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/libavutil/mem.c b/libavutil/mem.c
index c12c24aa90..3c014f3f68 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -510,12 +510,31 @@ 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);
}