MCPcopy Create free account
hub / github.com/defold/defold / resize

Function resize

engine/lua/src/lua/ltable.c: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

imageMethod · 0.85
initMethod · 0.85
imagefMethod · 0.85
imagefClass · 0.85
vector2DMethod · 0.85
pvrtc4_imageMethod · 0.85
vectorMethod · 0.85
vectorClass · 0.85
resetMethod · 0.85
enlargeMethod · 0.85
insertMethod · 0.85
uniqueMethod · 0.85

Calls 4

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

Tested by

no test coverage detected