MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / resize

Function resize

lua/ltable.c:331–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

329
330
331static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
332 int i;
333 int oldasize = t->sizearray;
334 int oldhsize = t->lsizenode;
335 Node *nold = t->node; /* save old hash ... */
336 if (nasize > oldasize) /* array part must grow? */
337 setarrayvector(L, t, nasize);
338 /* create new hash part with appropriate size */
339 setnodevector(L, t, nhsize);
340 if (nasize < oldasize) { /* array part must shrink? */
341 t->sizearray = nasize;
342 /* re-insert elements from vanishing slice */
343 for (i=nasize; i<oldasize; i++) {
344 if (!ttisnil(&t->array[i]))
345 setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]);
346 }
347 /* shrink array */
348 luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
349 }
350 /* re-insert elements from hash part */
351 for (i = twoto(oldhsize) - 1; i >= 0; i--) {
352 Node *old = nold+i;
353 if (!ttisnil(gval(old)))
354 setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));
355 }
356 if (nold != dummynode)
357 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
358}
359
360
361void luaH_resizearray (lua_State *L, Table *t, int nasize) {

Callers 2

luaH_resizearrayFunction · 0.85
rehashFunction · 0.85

Calls 4

setarrayvectorFunction · 0.85
setnodevectorFunction · 0.85
luaH_setnumFunction · 0.85
luaH_setFunction · 0.85

Tested by

no test coverage detected