Refactor table traversal.

Sponsored by OpenResty Inc.
This commit is contained in:
Mike Pall
2021-09-19 17:38:49 +02:00
parent 4e0ea654a8
commit c6f5ef649b
12 changed files with 156 additions and 210 deletions

View File

@@ -893,11 +893,13 @@ LUA_API int lua_next(lua_State *L, int idx)
cTValue *t = index2adr(L, idx);
int more;
lj_checkapi(tvistab(t), "stack slot %d is not a table", idx);
more = lj_tab_next(L, tabV(t), L->top-1);
if (more) {
more = lj_tab_next(tabV(t), L->top-1, L->top-1);
if (more > 0) {
incr_top(L); /* Return new key and value slot. */
} else { /* End of traversal. */
} else if (!more) { /* End of traversal. */
L->top--; /* Remove key slot. */
} else {
lj_err_msg(L, LJ_ERR_NEXTIDX);
}
return more;
}