qboolean Q_STShrink(stable_t *st, size_t newSize) { assert(st->st != NULL); // make sure that this is a valid resize if (newSize > MIN_SIZE && newSize < st->size) { // pack the string table into the smallest possible footprint int32_t size = nfst_pack((struct nfst_StringTable *)st->st); // if the string table can fit into if (size <= newSize) { void *new_one = NULL; if ((new_one = Z_Realloc(st->st, newSize)) != NULL) { st->st = new_one; st->size = newSize; nfst_grow((struct nfst_StringTable *)st->st, st->size); return true; } } // if it got here the allocation didn't change // either it's not small enough, or realloc failed // either way, expand the string table back to fit the allocation nfst_grow((struct nfst_StringTable *)st->st, st->size); } return false; }
int32_t Q_STPack(stable_t *st) { int32_t size = nfst_pack((struct nfst_StringTable *)st->st); if (st->heap && size > MIN_SIZE && size <= st->size/2) { void *new_one = NULL; if ((new_one = Z_Realloc(st->st, size)) != NULL) { st->st = new_one; st->size = size; } } return size; }
int32_t Q_STAutoPack(stable_t *st) { int32_t size; assert(st->st != NULL); size = nfst_pack((struct nfst_StringTable *)st->st); if (size <= st->size) { void *new_one = NULL; if ((new_one = Z_Realloc(st->st, size)) != NULL) { st->st = new_one; st->size = size; return size; } } // if the reallocation failed, expand the string table again nfst_grow((struct nfst_StringTable *)st->st, st->size); return st->size; }