diff options
author | Anton Khirnov <anton@khirnov.net> | 2011-04-29 17:33:38 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2011-04-29 17:34:56 +0200 |
commit | 35ceaa737643008e89a9ba54aaa9ebc0b57683b4 (patch) | |
tree | b6a90b5d1976897852082a35f5a56ef300a34d03 /libavutil/mem.c | |
parent | 9ac1bf88c00dbe7eb2191e2d5325fb104b9d8341 (diff) | |
download | ffmpeg-35ceaa737643008e89a9ba54aaa9ebc0b57683b4.tar.gz |
Move ff_dynarray_add to lavu and make it public.
Diffstat (limited to 'libavutil/mem.c')
-rw-r--r-- | libavutil/mem.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libavutil/mem.c b/libavutil/mem.c index 27bb30b8ef..85e1924e2b 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -171,3 +171,23 @@ char *av_strdup(const char *s) return ptr; } +/* add one element to a dynamic array */ +void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem) +{ + /* see similar ffmpeg.c:grow_array() */ + int nb, nb_alloc; + intptr_t *tab; + + nb = *nb_ptr; + tab = *(intptr_t**)tab_ptr; + if ((nb & (nb - 1)) == 0) { + if (nb == 0) + nb_alloc = 1; + else + nb_alloc = nb * 2; + tab = av_realloc(tab, nb_alloc * sizeof(intptr_t)); + *(intptr_t**)tab_ptr = tab; + } + tab[nb++] = (intptr_t)elem; + *nb_ptr = nb; +} |