MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / luaH_resize

Function luaH_resize

src/Chain/libraries/glua/ltable.cpp:469–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

467
468
469void luaH_resize(lua_State *L, Table *t, unsigned int nasize,
470 unsigned int nhsize) {
471 unsigned int i;
472 int j;
473 unsigned int oldasize = t->sizearray;
474 int oldhsize = t->lsizenode;
475 Node *nold = t->node; /* save old hash ... */
476 if (nasize > oldasize) /* array part must grow? */
477 setarrayvector(L, t, nasize);
478 /* create new hash part with appropriate size */
479 setnodevector(L, t, nhsize);
480 if (nasize < oldasize) { /* array part must shrink? */
481 t->sizearray = nasize;
482 /* re-insert elements from vanishing slice */
483 for (i = nasize; i < oldasize; i++) {
484 if (!ttisnil(&t->array[i]))
485 luaH_setint(L, t, i + 1, &t->array[i]);
486 }
487 /* shrink array */
488 luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
489 }
490 /* re-insert elements from hash part */
491 for (j = twoto(oldhsize) - 1; j >= 0; j--) {
492 Node *old = nold + j;
493 if (!ttisnil(gval(old))) {
494 /* doesn't need barrier/invalidate cache, as entry was
495 already present in the table */
496 setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
497 }
498 }
499 if (!isdummy(nold))
500 luaM_freearray(L, nold, lua_cast(size_t, twoto(oldhsize))); /* free old hash */
501}
502
503
504void luaH_resizearray(lua_State *L, Table *t, unsigned int nasize) {

Callers 5

vmcaseFunction · 0.85
luaH_resizearrayFunction · 0.85
rehashFunction · 0.85
init_registryFunction · 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