Move av_fast_{m,re}alloc from lavc to lavu.
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#endif
|
||||
|
||||
#include "avutil.h"
|
||||
#include "common.h"
|
||||
#include "intreadwrite.h"
|
||||
#include "mem.h"
|
||||
|
||||
@@ -344,3 +345,35 @@ void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
|
||||
*dst = *src;
|
||||
}
|
||||
}
|
||||
|
||||
void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
|
||||
{
|
||||
if (min_size < *size)
|
||||
return ptr;
|
||||
|
||||
min_size = FFMAX(17 * min_size / 16 + 32, min_size);
|
||||
|
||||
ptr = av_realloc(ptr, min_size);
|
||||
/* we could set this to the unmodified min_size but this is safer
|
||||
* if the user lost the ptr and uses NULL now
|
||||
*/
|
||||
if (!ptr)
|
||||
min_size = 0;
|
||||
|
||||
*size = min_size;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
|
||||
{
|
||||
void **p = ptr;
|
||||
if (min_size < *size)
|
||||
return;
|
||||
min_size = FFMAX(17 * min_size / 16 + 32, min_size);
|
||||
av_free(*p);
|
||||
*p = av_malloc(min_size);
|
||||
if (!*p)
|
||||
min_size = 0;
|
||||
*size = min_size;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user