diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-21 13:16:04 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-21 13:16:04 -0200 |
commit | ddc144e4d297e5e008f5693a568a1c74ac3e4f54 (patch) | |
tree | 273211ca4e0add6f5aa9e28b494e94d3267fbcc3 /lapi.c | |
parent | b48c6e768035a44ced1af0affa4b8c0970f1bdfd (diff) | |
download | lua-ddc144e4d297e5e008f5693a568a1c74ac3e4f54.tar.gz lua-ddc144e4d297e5e008f5693a568a1c74ac3e4f54.tar.bz2 lua-ddc144e4d297e5e008f5693a568a1c74ac3e4f54.zip |
keep L->ci->base in L->base for faster access
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 34 |
1 files changed, 17 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.220 2002/11/14 16:15:53 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.221 2002/11/21 14:16:52 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 | */ |
@@ -36,7 +36,7 @@ const char lua_ident[] = | |||
36 | #define api_check(L, o) /*{ assert(o); }*/ | 36 | #define api_check(L, o) /*{ assert(o); }*/ |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->ci->base)) | 39 | #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) |
40 | 40 | ||
41 | #define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} | 41 | #define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} |
42 | 42 | ||
@@ -45,14 +45,14 @@ const char lua_ident[] = | |||
45 | 45 | ||
46 | static TObject *negindex (lua_State *L, int index) { | 46 | static TObject *negindex (lua_State *L, int index) { |
47 | if (index > LUA_REGISTRYINDEX) { | 47 | if (index > LUA_REGISTRYINDEX) { |
48 | api_check(L, index != 0 && -index <= L->top - L->ci->base); | 48 | api_check(L, index != 0 && -index <= L->top - L->base); |
49 | return L->top+index; | 49 | return L->top+index; |
50 | } | 50 | } |
51 | else switch (index) { /* pseudo-indices */ | 51 | else switch (index) { /* pseudo-indices */ |
52 | case LUA_REGISTRYINDEX: return registry(L); | 52 | case LUA_REGISTRYINDEX: return registry(L); |
53 | case LUA_GLOBALSINDEX: return gt(L); | 53 | case LUA_GLOBALSINDEX: return gt(L); |
54 | default: { | 54 | default: { |
55 | TObject *func = (L->ci->base - 1); | 55 | TObject *func = (L->base - 1); |
56 | index = LUA_GLOBALSINDEX - index; | 56 | index = LUA_GLOBALSINDEX - index; |
57 | api_check(L, iscfunction(func) && index <= clvalue(func)->c.nupvalues); | 57 | api_check(L, iscfunction(func) && index <= clvalue(func)->c.nupvalues); |
58 | return &clvalue(func)->c.upvalue[index-1]; | 58 | return &clvalue(func)->c.upvalue[index-1]; |
@@ -63,8 +63,8 @@ static TObject *negindex (lua_State *L, int index) { | |||
63 | 63 | ||
64 | static TObject *luaA_index (lua_State *L, int index) { | 64 | static TObject *luaA_index (lua_State *L, int index) { |
65 | if (index > 0) { | 65 | if (index > 0) { |
66 | api_check(L, index <= L->top - L->ci->base); | 66 | api_check(L, index <= L->top - L->base); |
67 | return L->ci->base + index - 1; | 67 | return L->base + index - 1; |
68 | } | 68 | } |
69 | else | 69 | else |
70 | return negindex(L, index); | 70 | return negindex(L, index); |
@@ -73,8 +73,8 @@ static TObject *luaA_index (lua_State *L, int index) { | |||
73 | 73 | ||
74 | static TObject *luaA_indexAcceptable (lua_State *L, int index) { | 74 | static TObject *luaA_indexAcceptable (lua_State *L, int index) { |
75 | if (index > 0) { | 75 | if (index > 0) { |
76 | TObject *o = L->ci->base+(index-1); | 76 | TObject *o = L->base+(index-1); |
77 | api_check(L, index <= L->stack_last - L->ci->base); | 77 | api_check(L, index <= L->stack_last - L->base); |
78 | if (o >= L->top) return NULL; | 78 | if (o >= L->top) return NULL; |
79 | else return o; | 79 | else return o; |
80 | } | 80 | } |
@@ -92,7 +92,7 @@ void luaA_pushobject (lua_State *L, const TObject *o) { | |||
92 | LUA_API int lua_checkstack (lua_State *L, int size) { | 92 | LUA_API int lua_checkstack (lua_State *L, int size) { |
93 | int res; | 93 | int res; |
94 | lua_lock(L); | 94 | lua_lock(L); |
95 | if ((L->top - L->ci->base + size) > LUA_MAXCSTACK) | 95 | if ((L->top - L->base + size) > LUA_MAXCSTACK) |
96 | res = 0; /* stack overflow */ | 96 | res = 0; /* stack overflow */ |
97 | else { | 97 | else { |
98 | luaD_checkstack(L, size); | 98 | luaD_checkstack(L, size); |
@@ -148,20 +148,20 @@ LUA_API lua_State *lua_newthread (lua_State *L) { | |||
148 | 148 | ||
149 | 149 | ||
150 | LUA_API int lua_gettop (lua_State *L) { | 150 | LUA_API int lua_gettop (lua_State *L) { |
151 | return (L->top - L->ci->base); | 151 | return (L->top - L->base); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | LUA_API void lua_settop (lua_State *L, int index) { | 155 | LUA_API void lua_settop (lua_State *L, int index) { |
156 | lua_lock(L); | 156 | lua_lock(L); |
157 | if (index >= 0) { | 157 | if (index >= 0) { |
158 | api_check(L, index <= L->stack_last - L->ci->base); | 158 | api_check(L, index <= L->stack_last - L->base); |
159 | while (L->top < L->ci->base + index) | 159 | while (L->top < L->base + index) |
160 | setnilvalue(L->top++); | 160 | setnilvalue(L->top++); |
161 | L->top = L->ci->base + index; | 161 | L->top = L->base + index; |
162 | } | 162 | } |
163 | else { | 163 | else { |
164 | api_check(L, -(index+1) <= (L->top - L->ci->base)); | 164 | api_check(L, -(index+1) <= (L->top - L->base)); |
165 | L->top += index+1; /* `subtract' index (index is negative) */ | 165 | L->top += index+1; /* `subtract' index (index is negative) */ |
166 | } | 166 | } |
167 | lua_unlock(L); | 167 | lua_unlock(L); |
@@ -763,7 +763,7 @@ LUA_API void lua_concat (lua_State *L, int n) { | |||
763 | luaC_checkGC(L); | 763 | luaC_checkGC(L); |
764 | api_checknelems(L, n); | 764 | api_checknelems(L, n); |
765 | if (n >= 2) { | 765 | if (n >= 2) { |
766 | luaV_concat(L, n, L->top - L->ci->base - 1); | 766 | luaV_concat(L, n, L->top - L->base - 1); |
767 | L->top -= (n-1); | 767 | L->top -= (n-1); |
768 | } | 768 | } |
769 | else if (n == 0) { /* push empty string */ | 769 | else if (n == 0) { /* push empty string */ |
@@ -791,8 +791,8 @@ LUA_API int lua_pushupvalues (lua_State *L) { | |||
791 | Closure *func; | 791 | Closure *func; |
792 | int n, i; | 792 | int n, i; |
793 | lua_lock(L); | 793 | lua_lock(L); |
794 | api_check(L, iscfunction(L->ci->base - 1)); | 794 | api_check(L, iscfunction(L->base - 1)); |
795 | func = clvalue(L->ci->base - 1); | 795 | func = clvalue(L->base - 1); |
796 | n = func->c.nupvalues; | 796 | n = func->c.nupvalues; |
797 | luaD_checkstack(L, n + LUA_MINSTACK); | 797 | luaD_checkstack(L, n + LUA_MINSTACK); |
798 | for (i=0; i<n; i++) { | 798 | for (i=0; i<n; i++) { |