MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaH_resize

Function luaH_resize

depends/lua/src/ltable.c:347–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345
346
347void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
348 unsigned int nhsize) {
349 unsigned int i;
350 int j;
351 AuxsetnodeT asn;
352 unsigned int oldasize = t->sizearray;
353 int oldhsize = allocsizenode(t);
354 Node *nold = t->node; /* save old hash ... */
355 if (nasize > oldasize) /* array part must grow? */
356 setarrayvector(L, t, nasize);
357 /* create new hash part with appropriate size */
358 asn.t = t; asn.nhsize = nhsize;
359 if (luaD_rawrunprotected(L, auxsetnode, &asn) != LUA_OK) { /* mem. error? */
360 setarrayvector(L, t, oldasize); /* array back to its original size */
361 luaD_throw(L, LUA_ERRMEM); /* rethrow memory error */
362 }
363 if (nasize < oldasize) { /* array part must shrink? */
364 t->sizearray = nasize;
365 /* re-insert elements from vanishing slice */
366 for (i=nasize; i<oldasize; i++) {
367 if (!ttisnil(&t->array[i]))
368 luaH_setint(L, t, i + 1, &t->array[i]);
369 }
370 /* shrink array */
371 luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
372 }
373 /* re-insert elements from hash part */
374 for (j = oldhsize - 1; j >= 0; j--) {
375 Node *old = nold + j;
376 if (!ttisnil(gval(old))) {
377 /* doesn't need barrier/invalidate cache, as entry was
378 already present in the table */
379 setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
380 }
381 }
382 if (oldhsize > 0) /* not the dummy node? */
383 luaM_freearray(L, nold, cast(size_t, oldhsize)); /* free old hash */
384}
385
386
387void 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 6

setarrayvectorFunction · 0.85
luaD_rawrunprotectedFunction · 0.85
luaD_throwFunction · 0.85
luaH_setintFunction · 0.85
luaH_setFunction · 0.85
castFunction · 0.85

Tested by

no test coverage detected