diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-01 16:20:48 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-01 16:20:48 -0200 |
commit | b9e76be8a691ed83a716a85c6b85cb80f66cc480 (patch) | |
tree | 851df615f2cb00ba1bdf4042336a56b7c4609a40 /lapi.c | |
parent | c5482468fde11c6c169da3b331a0653455f8fc94 (diff) | |
download | lua-b9e76be8a691ed83a716a85c6b85cb80f66cc480.tar.gz lua-b9e76be8a691ed83a716a85c6b85cb80f66cc480.tar.bz2 lua-b9e76be8a691ed83a716a85c6b85cb80f66cc480.zip |
using 'L->func' when possible
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 25 |
1 files changed, 12 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.270 2017/06/29 15:06:44 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.271 2017/10/11 12:38:45 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -60,13 +60,13 @@ const char lua_ident[] = | |||
60 | static TValue *index2value (lua_State *L, int idx) { | 60 | static TValue *index2value (lua_State *L, int idx) { |
61 | CallInfo *ci = L->ci; | 61 | CallInfo *ci = L->ci; |
62 | if (idx > 0) { | 62 | if (idx > 0) { |
63 | StkId o = ci->func + idx; | 63 | StkId o = L->func + idx; |
64 | api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index"); | 64 | api_check(L, idx <= ci->top - (L->func + 1), "unacceptable index"); |
65 | if (o >= L->top) return NONVALIDVALUE; | 65 | if (o >= L->top) return NONVALIDVALUE; |
66 | else return s2v(o); | 66 | else return s2v(o); |
67 | } | 67 | } |
68 | else if (!ispseudo(idx)) { /* negative index */ | 68 | else if (!ispseudo(idx)) { /* negative index */ |
69 | api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); | 69 | api_check(L, idx != 0 && -idx <= L->top - (L->func + 1), "invalid index"); |
70 | return s2v(L->top + idx); | 70 | return s2v(L->top + idx); |
71 | } | 71 | } |
72 | else if (idx == LUA_REGISTRYINDEX) | 72 | else if (idx == LUA_REGISTRYINDEX) |
@@ -74,10 +74,10 @@ static TValue *index2value (lua_State *L, int idx) { | |||
74 | else { /* upvalues */ | 74 | else { /* upvalues */ |
75 | idx = LUA_REGISTRYINDEX - idx; | 75 | idx = LUA_REGISTRYINDEX - idx; |
76 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); | 76 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); |
77 | if (ttislcf(s2v(ci->func))) /* light C function? */ | 77 | if (ttislcf(s2v(L->func))) /* light C function? */ |
78 | return NONVALIDVALUE; /* it has no upvalues */ | 78 | return NONVALIDVALUE; /* it has no upvalues */ |
79 | else { | 79 | else { |
80 | CClosure *func = clCvalue(s2v(ci->func)); | 80 | CClosure *func = clCvalue(s2v(L->func)); |
81 | return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE; | 81 | return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE; |
82 | } | 82 | } |
83 | } | 83 | } |
@@ -85,14 +85,13 @@ static TValue *index2value (lua_State *L, int idx) { | |||
85 | 85 | ||
86 | 86 | ||
87 | static StkId index2stack (lua_State *L, int idx) { | 87 | static StkId index2stack (lua_State *L, int idx) { |
88 | CallInfo *ci = L->ci; | ||
89 | if (idx > 0) { | 88 | if (idx > 0) { |
90 | StkId o = ci->func + idx; | 89 | StkId o = L->func + idx; |
91 | api_check(L, o < L->top, "unacceptable index"); | 90 | api_check(L, o < L->top, "unacceptable index"); |
92 | return o; | 91 | return o; |
93 | } | 92 | } |
94 | else { /* non-positive index */ | 93 | else { /* non-positive index */ |
95 | api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); | 94 | api_check(L, idx != 0 && -idx <= L->top - (L->func + 1), "invalid index"); |
96 | api_check(L, !ispseudo(idx), "invalid index"); | 95 | api_check(L, !ispseudo(idx), "invalid index"); |
97 | return L->top + idx; | 96 | return L->top + idx; |
98 | } | 97 | } |
@@ -175,17 +174,17 @@ LUA_API const lua_Number *lua_version (lua_State *L) { | |||
175 | LUA_API int lua_absindex (lua_State *L, int idx) { | 174 | LUA_API int lua_absindex (lua_State *L, int idx) { |
176 | return (idx > 0 || ispseudo(idx)) | 175 | return (idx > 0 || ispseudo(idx)) |
177 | ? idx | 176 | ? idx |
178 | : cast_int(L->top - L->ci->func) + idx; | 177 | : cast_int(L->top - L->func) + idx; |
179 | } | 178 | } |
180 | 179 | ||
181 | 180 | ||
182 | LUA_API int lua_gettop (lua_State *L) { | 181 | LUA_API int lua_gettop (lua_State *L) { |
183 | return cast_int(L->top - (L->ci->func + 1)); | 182 | return cast_int(L->top - (L->func + 1)); |
184 | } | 183 | } |
185 | 184 | ||
186 | 185 | ||
187 | LUA_API void lua_settop (lua_State *L, int idx) { | 186 | LUA_API void lua_settop (lua_State *L, int idx) { |
188 | StkId func = L->ci->func; | 187 | StkId func = L->func; |
189 | lua_lock(L); | 188 | lua_lock(L); |
190 | if (idx >= 0) { | 189 | if (idx >= 0) { |
191 | api_check(L, idx <= L->stack_last - (func + 1), "new top too large"); | 190 | api_check(L, idx <= L->stack_last - (func + 1), "new top too large"); |
@@ -243,7 +242,7 @@ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { | |||
243 | api_checkvalidindex(L, to); | 242 | api_checkvalidindex(L, to); |
244 | setobj(L, to, fr); | 243 | setobj(L, to, fr); |
245 | if (isupvalue(toidx)) /* function upvalue? */ | 244 | if (isupvalue(toidx)) /* function upvalue? */ |
246 | luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr); | 245 | luaC_barrier(L, clCvalue(s2v(L->func)), fr); |
247 | /* LUA_REGISTRYINDEX does not need gc barrier | 246 | /* LUA_REGISTRYINDEX does not need gc barrier |
248 | (collector revisits it before finishing collection) */ | 247 | (collector revisits it before finishing collection) */ |
249 | lua_unlock(L); | 248 | lua_unlock(L); |