MCPcopy Create free account
hub / github.com/BigPig0/RelayLive / luaH_resize

Function luaH_resize

ThirdParty/lua/lua/ltable.c:335–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333
334
335void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
336 unsigned int nhsize) {
337 unsigned int i;
338 int j;
339 unsigned int oldasize = t->sizearray;
340 int oldhsize = t->lsizenode;
341 Node *nold = t->node; /* save old hash ... */
342 if (nasize > oldasize) /* array part must grow? */
343 setarrayvector(L, t, nasize);
344 /* create new hash part with appropriate size */
345 setnodevector(L, t, nhsize);
346 if (nasize < oldasize) { /* array part must shrink? */
347 t->sizearray = nasize;
348 /* re-insert elements from vanishing slice */
349 for (i=nasize; i<oldasize; i++) {
350 if (!ttisnil(&t->array[i]))
351 luaH_setint(L, t, i + 1, &t->array[i]);
352 }
353 /* shrink array */
354 luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
355 }
356 /* re-insert elements from hash part */
357 for (j = twoto(oldhsize) - 1; j >= 0; j--) {
358 Node *old = nold + j;
359 if (!ttisnil(gval(old))) {
360 /* doesn't need barrier/invalidate cache, as entry was
361 already present in the table */
362 setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
363 }
364 }
365 if (!isdummy(nold))
366 luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */
367}
368
369
370void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) {

Callers 5

luaV_executeFunction · 0.85
init_registryFunction · 0.85
luaH_resizearrayFunction · 0.85
rehashFunction · 0.85
lua_createtableFunction · 0.85

Calls 4

setarrayvectorFunction · 0.85
setnodevectorFunction · 0.85
luaH_setintFunction · 0.85
luaH_setFunction · 0.85

Tested by

no test coverage detected