private static void luaH_resize(lua_State L, Table t, uint nasize, uint nhsize) { uint i; int j; AuxsetnodeT asn = new AuxsetnodeT(); uint oldasize = t.sizearray; int oldhsize = allocsizenode(t); Node[] nold = t.node; /* save old hash ... */ // Debug.WriteLine("x001=" + nasize + ",x002=" + nhsize); if (nasize > oldasize) /* array part must grow? */ { setarrayvector(L, t, nasize); } /* create new hash part with appropriate size */ asn.t = t; asn.nhsize = nhsize; if (luaD_rawrunprotected(L, auxsetnode, asn) != LUA_OK) /* mem. error? */ { setarrayvector(L, t, oldasize); /* array back to its original size */ luaD_throw(L, LUA_ERRMEM); /* rethrow memory error */ } if (nasize < oldasize) /* array part must shrink? */ { t.sizearray = nasize; /* re-insert elements from vanishing slice */ for (i = nasize; i < oldasize; i++) { if (!ttisnil(t.array[i])) { luaH_setint(L, t, (int)(i + 1), t.array[i]); } } /* shrink array */ luaM_reallocvector <TValue>(L, ref t.array, (int)oldasize, (int)nasize /*, TValue*/); } /* re-insert elements from hash part */ for (j = oldhsize - 1; j >= 0; j--) { Node old = nold[j]; if (!ttisnil(gval(old))) { /* doesn't need barrier/invalidate cache, as entry was * already present in the table */ setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old)); } } if (oldhsize > 0) /* not the dummy node? */ { luaM_freearray(L, nold); //luaM_freearray(L, nold, (uint)(oldhsize)); /* free old hash */ } }
private static void auxsetnode(lua_State L, object ud) { AuxsetnodeT asn = (AuxsetnodeT)(ud); setnodevector(L, asn.t, asn.nhsize); }