Skip to content

Commit

Permalink
Revert "Merge pull request #131 from PlutoLang/optimize-tinsert"
Browse files Browse the repository at this point in the history
This reverts commit 552e239 due to issues with inserting to tables after one of its entries has been set to nil, causing unwanted behaviour i.e. dropping entries that weren't nil.
  • Loading branch information
Sainan committed Nov 11, 2022
1 parent 2eca8cf commit e2a4f84
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/ltablib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static void checktab (lua_State *L, int arg, int what) {
}


LUAI_FUNC int tinsert (lua_State *L) {
static int tinsert (lua_State *L) {
lua_Integer pos; /* where to insert new element */
lua_Integer e = aux_getn(L, 1, TAB_RW);
e = luaL_intop(+, e, 1); /* first empty element */
Expand Down
26 changes: 9 additions & 17 deletions src/lvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,6 @@ void luaV_finishOp (lua_State *L) {
*/
LUAI_FUNC int luaB_next (lua_State *L);
LUAI_FUNC int luaB_ipairsaux (lua_State *L);
LUAI_FUNC int tinsert(lua_State * L);


#ifdef PLUTO_VMDUMP
Expand Down Expand Up @@ -2185,23 +2184,16 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
#ifdef PLUTO_ILP_HOOK_FUNCTION
if (fvalue(s2v(ra)) == PLUTO_ILP_HOOK_FUNCTION) sequentialJumps = 0;
#endif
if (fvalue(s2v(ra)) == tinsert && ttistable(s2v(ra + 1)) && ttisnil(s2v(ra + 3))) {
Table* table = hvalue(s2v(ra + 1));
if (!table->length) table->length = luaH_getn(table); /* ensure table has cached length */
luaH_setint(L, table, ++table->length, s2v(ra + 2));
if ((newci = luaD_precall(L, ra, nresults)) == NULL) /* C call; nothing else to be done */
{
updatetrap(ci);
vmDumpOut("; call cfunc (nresults=" << nresults << " nparams=" << nresults << ")");
}
else {
if ((newci = luaD_precall(L, ra, nresults)) == NULL) /* C call; nothing else to be done */
{
updatetrap(ci);
vmDumpOut("; call cfunc (nresults=" << nresults << " nparams=" << nresults << ")");
}
else /* Lua call: run function in this same C frame */
{
vmDumpOut("; call lfunc (nresults=" << nresults << " nparams=" << nresults << ")");
ci = newci;
goto startfunc;
}
else /* Lua call: run function in this same C frame */
{
vmDumpOut("; call lfunc (nresults=" << nresults << " nparams=" << nresults << ")");
ci = newci;
goto startfunc;
}
vmbreak;
}
Expand Down
21 changes: 0 additions & 21 deletions tests/bench/tinsert.lua

This file was deleted.

0 comments on commit e2a4f84

Please sign in to comment.