allocator.c (615B)
1 /* See LICENSE file for copyright and license details. */ 2 #include "internals.h" 3 4 5 void 6 libzahl_realloc(z_t a, size_t need) 7 { 8 size_t i, new_size = 1; 9 zahl_char_t *new; 10 11 new_size <<= i = libzahl_msb_nz_zu(need); 12 if (likely(new_size != need)) { 13 i += 1; 14 new_size <<= 1; 15 } 16 17 if (likely(libzahl_pool_n[i])) { 18 libzahl_pool_n[i]--; 19 new = libzahl_pool[i][libzahl_pool_n[i]]; 20 zmemcpy(new, a->chars, a->alloced); 21 zfree(a); 22 a->chars = new; 23 } else { 24 a->chars = realloc(a->chars, (new_size + ZAHL_FLUFF) * sizeof(zahl_char_t)); 25 if (check(!a->chars)) 26 libzahl_memfailure(); 27 } 28 a->alloced = new_size; 29 }