revamp of fast track for table access (table set uses the same
macros as table get + new macro for integer keys)
This commit is contained in:
41
lapi.c
41
lapi.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lapi.c,v 2.264 2017/04/20 18:22:44 roberto Exp roberto $
|
||||
** $Id: lapi.c,v 2.265 2017/04/24 16:59:26 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -609,10 +609,15 @@ LUA_API int lua_getglobal (lua_State *L, const char *name) {
|
||||
|
||||
|
||||
LUA_API int lua_gettable (lua_State *L, int idx) {
|
||||
const TValue *slot;
|
||||
StkId t;
|
||||
lua_lock(L);
|
||||
t = index2addr(L, idx);
|
||||
luaV_gettable(L, t, L->top - 1, L->top - 1);
|
||||
if (luaV_fastget(L, t, L->top - 1, slot, luaH_get)) {
|
||||
setobj2s(L, L->top - 1, slot);
|
||||
}
|
||||
else
|
||||
luaV_finishget(L, t, L->top - 1, L->top - 1, slot);
|
||||
lua_unlock(L);
|
||||
return ttnov(L->top - 1);
|
||||
}
|
||||
@@ -629,15 +634,15 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
|
||||
const TValue *slot;
|
||||
lua_lock(L);
|
||||
t = index2addr(L, idx);
|
||||
if (luaV_fastget(L, t, n, slot, luaH_getint)) {
|
||||
if (luaV_fastgeti(L, t, n, slot)) {
|
||||
setobj2s(L, L->top, slot);
|
||||
api_incr_top(L);
|
||||
}
|
||||
else {
|
||||
setivalue(L->top, n);
|
||||
api_incr_top(L);
|
||||
luaV_finishget(L, t, L->top - 1, L->top - 1, slot);
|
||||
TValue aux;
|
||||
setivalue(&aux, n);
|
||||
luaV_finishget(L, t, &aux, L->top, slot);
|
||||
}
|
||||
api_incr_top(L);
|
||||
lua_unlock(L);
|
||||
return ttnov(L->top - 1);
|
||||
}
|
||||
@@ -743,8 +748,10 @@ static void auxsetstr (lua_State *L, const TValue *t, const char *k) {
|
||||
const TValue *slot;
|
||||
TString *str = luaS_new(L, k);
|
||||
api_checknelems(L, 1);
|
||||
if (luaV_fastset(L, t, str, slot, luaH_getstr, L->top - 1))
|
||||
if (luaV_fastget(L, t, str, slot, luaH_getstr)) {
|
||||
luaV_finishfastset(L, t, slot, L->top - 1);
|
||||
L->top--; /* pop value */
|
||||
}
|
||||
else {
|
||||
setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */
|
||||
api_incr_top(L);
|
||||
@@ -764,10 +771,14 @@ LUA_API void lua_setglobal (lua_State *L, const char *name) {
|
||||
|
||||
LUA_API void lua_settable (lua_State *L, int idx) {
|
||||
StkId t;
|
||||
const TValue *slot;
|
||||
lua_lock(L);
|
||||
api_checknelems(L, 2);
|
||||
t = index2addr(L, idx);
|
||||
luaV_settable(L, t, L->top - 2, L->top - 1);
|
||||
if (luaV_fastget(L, t, L->top - 2, slot, luaH_get))
|
||||
luaV_finishfastset(L, t, slot, L->top - 1);
|
||||
else
|
||||
luaV_finishset(L, t, L->top - 2, L->top - 1, slot);
|
||||
L->top -= 2; /* pop index and value */
|
||||
lua_unlock(L);
|
||||
}
|
||||
@@ -785,14 +796,14 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
|
||||
lua_lock(L);
|
||||
api_checknelems(L, 1);
|
||||
t = index2addr(L, idx);
|
||||
if (luaV_fastset(L, t, n, slot, luaH_getint, L->top - 1))
|
||||
L->top--; /* pop value */
|
||||
if (luaV_fastgeti(L, t, n, slot))
|
||||
luaV_finishfastset(L, t, slot, L->top - 1);
|
||||
else {
|
||||
setivalue(L->top, n);
|
||||
api_incr_top(L);
|
||||
luaV_finishset(L, t, L->top - 1, L->top - 2, slot);
|
||||
L->top -= 2; /* pop value and key */
|
||||
TValue aux;
|
||||
setivalue(&aux, n);
|
||||
luaV_finishset(L, t, &aux, L->top - 1, slot);
|
||||
}
|
||||
L->top--; /* pop value */
|
||||
lua_unlock(L);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user