Mercurial > audlegacy
diff src/audacious/util.c @ 4267:a41fb6bc632a
- src stuff traveled to src_flow.c
- vis works again.
| author | Eugene Zagidullin <e.asphyx@gmail.com> |
|---|---|
| date | Sun, 10 Feb 2008 07:19:45 +0300 |
| parents | 92642f860860 |
| children | 0a9e1d9eae7b |
line wrap: on
line diff
--- a/src/audacious/util.c Sat Feb 09 01:05:36 2008 +0300 +++ b/src/audacious/util.c Sun Feb 10 07:19:45 2008 +0300 @@ -37,6 +37,7 @@ #include <stdlib.h> #include <string.h> #include <ctype.h> +#include <math.h> #include "platform/smartinclude.h" #include <errno.h> @@ -1056,3 +1057,19 @@ AUDDBG("uri=%s\n", uri); return uri; } + +/* + * minimize number of realloc's: + * - set N to nearest power of 2 not less then N + * - double it + * + * -- asphyx + */ +void* +smart_realloc(void *ptr, size_t *size) { + *size = (size_t)pow(2, ceil(log(*size) / log(2)) + 1); + if (ptr != NULL) free(ptr); + ptr = malloc(*size); + return ptr; +} +
