aboutsummaryrefslogtreecommitdiff
path: root/opcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-24 19:59:57 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-24 19:59:57 -0300
commit369dd65318488ca888fc76c5667be3a713257aa6 (patch)
treebb9e5d6abc397d44b1e9bf8b3d21bcf663fe4f5e /opcode.c
parent209602ac31512c9f201d11edca6fe7aa368b85a4 (diff)
downloadlua-369dd65318488ca888fc76c5667be3a713257aa6.tar.gz
lua-369dd65318488ca888fc76c5667be3a713257aa6.tar.bz2
lua-369dd65318488ca888fc76c5667be3a713257aa6.zip
small optimization in the access to i.m. table.
Diffstat (limited to 'opcode.c')
-rw-r--r--opcode.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/opcode.c b/opcode.c
index 77b680d6..066e9c05 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 4.2 1997/04/04 22:24:51 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 4.3 1997/04/15 17:32:47 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -180,11 +180,14 @@ static int lua_tostring (TObject *obj)
180*/ 180*/
181static void adjust_top (StkId newtop) 181static void adjust_top (StkId newtop)
182{ 182{
183 TObject *nt; 183 if (newtop <= top-stack) /* int arith, since newtop may be out of stack */
184 lua_checkstack(stack+newtop); 184 top = stack+newtop;
185 nt = stack+newtop; /* warning: previous call may change stack */ 185 else {
186 while (top < nt) ttype(top++) = LUA_T_NIL; 186 TObject *nt;
187 top = nt; /* top could be bigger than newtop */ 187 lua_checkstack(stack+newtop);
188 nt = stack+newtop; /* warning: previous call may change stack */
189 while (top < nt) ttype(top++) = LUA_T_NIL;
190 }
188} 191}
189 192
190#define adjustC(nParams) adjust_top(CLS_current.base+nParams) 193#define adjustC(nParams) adjust_top(CLS_current.base+nParams)
@@ -300,7 +303,7 @@ static void do_call (StkId base, int nResults)
300 return; 303 return;
301 } 304 }
302 /* adjust the number of results */ 305 /* adjust the number of results */
303 if (nResults != MULT_RET && top - (stack+firstResult) != nResults) 306 if (nResults != MULT_RET)
304 adjust_top(firstResult+nResults); 307 adjust_top(firstResult+nResults);
305 /* move results to base-1 (to erase parameters and function) */ 308 /* move results to base-1 (to erase parameters and function) */
306 base--; 309 base--;
@@ -317,7 +320,7 @@ static void do_call (StkId base, int nResults)
317*/ 320*/
318static void pushsubscript (void) 321static void pushsubscript (void)
319{ 322{
320 int tg = luaI_tag(top-2); 323 int tg = luaI_efectivetag(top-2);
321 TObject *im = luaI_getim(tg, IM_GETTABLE); 324 TObject *im = luaI_getim(tg, IM_GETTABLE);
322 if (ttype(top-2) == LUA_T_ARRAY && ttype(im) == LUA_T_NIL) { 325 if (ttype(top-2) == LUA_T_ARRAY && ttype(im) == LUA_T_NIL) {
323 TObject *h = lua_hashget(avalue(top-2), top-1); 326 TObject *h = lua_hashget(avalue(top-2), top-1);
@@ -1033,9 +1036,18 @@ void lua_pushobject (lua_Object o)
1033 incr_top; 1036 incr_top;
1034} 1037}
1035 1038
1036int lua_tag (lua_Object o) 1039int lua_tag (lua_Object lo)
1037{ 1040{
1038 return (o == LUA_NOOBJECT) ? LUA_T_NIL : luaI_tag(Address(o)); 1041 if (lo == LUA_NOOBJECT) return LUA_T_NIL;
1042 else {
1043 TObject *o = Address(lo);
1044 lua_Type t = ttype(o);
1045 if (t == LUA_T_USERDATA)
1046 return o->value.ts->tag;
1047 else if (t == LUA_T_ARRAY)
1048 return o->value.a->htag;
1049 else return t;
1050 }
1039} 1051}
1040 1052
1041 1053