MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaH_resize

Function luaH_resize

third-party/lua-5.5.0/src/ltable.c:716–748  ·  view source on GitHub ↗

** Resize table 't' for the new given sizes. Both allocations (for ** the hash part and for the array part) can fail, which creates some ** subtleties. If the first allocation, for the hash part, fails, an ** error is raised and that is it. Otherwise, it copies the elements from ** the shrinking part of the array (if it is shrinking) into the new ** hash. Then it reallocates the array part. If th

Source from the content-addressed store, hash-verified

714** part.
715*/
716void luaH_resize (lua_State *L, Table *t, unsigned newasize,
717 unsigned nhsize) {
718 Table newt; /* to keep the new hash part */
719 unsigned oldasize = t->asize;
720 Value *newarray;
721 if (newasize > MAXASIZE)
722 luaG_runerror(L, "table overflow");
723 /* create new hash part with appropriate size into 'newt' */
724 newt.flags = 0;
725 setnodevector(L, &newt, nhsize);
726 if (newasize < oldasize) { /* will array shrink? */
727 /* re-insert into the new hash the elements from vanishing slice */
728 exchangehashpart(t, &newt); /* pretend table has new hash */
729 reinsertOldSlice(t, oldasize, newasize);
730 exchangehashpart(t, &newt); /* restore old hash (in case of errors) */
731 }
732 /* allocate new array */
733 newarray = resizearray(L, t, oldasize, newasize);
734 if (l_unlikely(newarray == NULL && newasize > 0)) { /* allocation failed? */
735 freehash(L, &newt); /* release new hash part */
736 luaM_error(L); /* raise error (with array unchanged) */
737 }
738 /* allocation ok; initialize new part of the array */
739 exchangehashpart(t, &newt); /* 't' has the new hash ('newt' has the old) */
740 t->array = newarray; /* set new array part */
741 t->asize = newasize;
742 if (newarray != NULL)
743 *lenhint(t) = newasize / 2u; /* set an initial hint */
744 clearNewSlice(t, oldasize, newasize);
745 /* re-insert elements from old hash part into new parts */
746 reinserthash(L, &newt, t); /* 'newt' now has the old hash */
747 freehash(L, &newt); /* free old hash part */
748}
749
750
751void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) {

Callers 6

luaV_executeFunction · 0.70
init_registryFunction · 0.70
createvarargtabFunction · 0.70
luaH_resizearrayFunction · 0.70
rehashFunction · 0.70
lua_createtableFunction · 0.70

Calls 8

reinsertOldSliceFunction · 0.85
resizearrayFunction · 0.85
clearNewSliceFunction · 0.85
reinserthashFunction · 0.85
luaG_runerrorFunction · 0.70
setnodevectorFunction · 0.70
exchangehashpartFunction · 0.70
freehashFunction · 0.70

Tested by

no test coverage detected