MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / resize

Function resize

other_src/lua/src/ltable.cpp:297–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

295
296
297static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
298 int i;
299 int oldasize = t->sizearray;
300 int oldhsize = t->lsizenode;
301 Node *nold = t->node; /* save old hash ... */
302 if (nasize > oldasize) /* array part must grow? */
303 setarrayvector(L, t, nasize);
304 /* create new hash part with appropriate size */
305 setnodevector(L, t, nhsize);
306 if (nasize < oldasize) { /* array part must shrink? */
307 t->sizearray = nasize;
308 /* re-insert elements from vanishing slice */
309 for (i=nasize; i<oldasize; i++) {
310 if (!ttisnil(&t->array[i]))
311 setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]);
312 }
313 /* shrink array */
314 luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
315 }
316 /* re-insert elements from hash part */
317 for (i = twoto(oldhsize) - 1; i >= 0; i--) {
318 Node *old = nold+i;
319 if (!ttisnil(gval(old)))
320 setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));
321 }
322 if (nold != dummynode)
323 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
324}
325
326
327void luaH_resizearray (lua_State *L, Table *t, int nasize) {

Callers 15

luaH_resizearrayFunction · 0.70
rehashFunction · 0.70
updateMethod · 0.50
resizeMethod · 0.50
resizeMethod · 0.50
resizeMethod · 0.50
resizeMethod · 0.50
resizeMethod · 0.50
resizeMethod · 0.50
resizeMethod · 0.50
ControlPanelMethod · 0.50
renderMethod · 0.50

Calls 4

setarrayvectorFunction · 0.70
setnodevectorFunction · 0.70
luaH_setnumFunction · 0.70
luaH_setFunction · 0.70

Tested by

no test coverage detected