MCPcopy Create free account
hub / github.com/F-Stack/f-stack / luaH_resize

Function luaH_resize

freebsd/contrib/openzfs/module/lua/ltable.c:304–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302
303
304void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
305 int i;
306 int oldasize = t->sizearray;
307 int oldhsize = t->lsizenode;
308 Node *nold = t->node; /* save old hash ... */
309 if (nasize > oldasize) /* array part must grow? */
310 setarrayvector(L, t, nasize);
311 /* create new hash part with appropriate size */
312 setnodevector(L, t, nhsize);
313 if (nasize < oldasize) { /* array part must shrink? */
314 t->sizearray = nasize;
315 /* re-insert elements from vanishing slice */
316 for (i=nasize; i<oldasize; i++) {
317 if (!ttisnil(&t->array[i]))
318 luaH_setint(L, t, i + 1, &t->array[i]);
319 }
320 /* shrink array */
321 luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
322 }
323 /* re-insert elements from hash part */
324 for (i = twoto(oldhsize) - 1; i >= 0; i--) {
325 Node *old = nold+i;
326 if (!ttisnil(gval(old))) {
327 /* doesn't need barrier/invalidate cache, as entry was
328 already present in the table */
329 setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
330 }
331 }
332 if (!isdummy(nold))
333 luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */
334}
335
336
337void luaH_resizearray (lua_State *L, Table *t, 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

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

Tested by

no test coverage detected