MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / luaH_resize

Function luaH_resize

libraries/AP_Scripting/lua/src/ltable.c:354–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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

Tested by

no test coverage detected