diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-24 14:20:54 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-24 14:20:54 -0200 |
commit | c8559e3c8d12e052783e2952db1372c68cc16059 (patch) | |
tree | e46b2caaf0d2933a1e562bd52ef1420d38b24912 | |
parent | 71ae4801d66d9592b0fb08e4e78138b7a6e993d5 (diff) | |
download | lua-c8559e3c8d12e052783e2952db1372c68cc16059.tar.gz lua-c8559e3c8d12e052783e2952db1372c68cc16059.tar.bz2 lua-c8559e3c8d12e052783e2952db1372c68cc16059.zip |
a small optimization
-rw-r--r-- | ltm.h | 17 | ||||
-rw-r--r-- | lvm.c | 12 |
2 files changed, 23 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.h,v 1.19 2000/12/26 18:46:09 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 1.20 2001/01/19 13:20:30 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -35,6 +35,21 @@ typedef enum { | |||
35 | } TMS; | 35 | } TMS; |
36 | 36 | ||
37 | 37 | ||
38 | |||
39 | /* | ||
40 | ** masks for allowable tag methods | ||
41 | */ | ||
42 | #define HAS_TM_GETGLOBAL(L,t) (1<<(t) & ((1<<LUA_TUSERDATA) | \ | ||
43 | (1<<LUA_TTABLE) | \ | ||
44 | (1<<LUA_TNIL))) | ||
45 | |||
46 | #define HAS_TM_SETGLOBAL(L,t) (1<<(t) & ((1<<LUA_TUSERDATA) | \ | ||
47 | (1<<LUA_TTABLE) | \ | ||
48 | (1<<LUA_TNIL) | \ | ||
49 | (1<<LUA_TFUNCTION))) | ||
50 | |||
51 | |||
52 | |||
38 | struct TM { | 53 | struct TM { |
39 | Closure *method[TM_N]; | 54 | Closure *method[TM_N]; |
40 | TString *collected; /* list of garbage-collected udata with this tag */ | 55 | TString *collected; /* list of garbage-collected udata with this tag */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.155 2001/01/19 13:20:30 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.156 2001/01/24 15:45:33 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -174,8 +174,9 @@ void luaV_settable (lua_State *L, StkId t, StkId key) { | |||
174 | 174 | ||
175 | const TObject *luaV_getglobal (lua_State *L, TString *s) { | 175 | const TObject *luaV_getglobal (lua_State *L, TString *s) { |
176 | const TObject *value = luaH_getstr(L->gt, s); | 176 | const TObject *value = luaH_getstr(L->gt, s); |
177 | Closure *tm = luaT_gettmbyObj(G(L), value, TM_GETGLOBAL); | 177 | Closure *tm; |
178 | if (tm == NULL) /* is there a tag method? */ | 178 | if (!HAS_TM_GETGLOBAL(L, ttype(value)) || /* is there a tag method? */ |
179 | (tm = luaT_gettmbyObj(G(L), value, TM_GETGLOBAL)) == NULL) | ||
179 | return value; /* default behavior */ | 180 | return value; /* default behavior */ |
180 | else { /* tag method */ | 181 | else { /* tag method */ |
181 | luaD_checkstack(L, 3); | 182 | luaD_checkstack(L, 3); |
@@ -191,8 +192,9 @@ const TObject *luaV_getglobal (lua_State *L, TString *s) { | |||
191 | 192 | ||
192 | void luaV_setglobal (lua_State *L, TString *s) { | 193 | void luaV_setglobal (lua_State *L, TString *s) { |
193 | TObject *oldvalue = luaH_setstr(L, L->gt, s); | 194 | TObject *oldvalue = luaH_setstr(L, L->gt, s); |
194 | Closure *tm = luaT_gettmbyObj(G(L), oldvalue, TM_SETGLOBAL); | 195 | Closure *tm; |
195 | if (tm == NULL) { /* no tag methods? */ | 196 | if (!HAS_TM_SETGLOBAL(L, ttype(oldvalue)) || /* no tag methods? */ |
197 | (tm = luaT_gettmbyObj(G(L), oldvalue, TM_SETGLOBAL)) == NULL) { | ||
196 | setobj(oldvalue, L->top - 1); /* raw set */ | 198 | setobj(oldvalue, L->top - 1); /* raw set */ |
197 | } | 199 | } |
198 | else { /* call tag method */ | 200 | else { /* call tag method */ |