diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-01-15 11:14:24 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-01-15 11:14:24 -0200 |
commit | b5eb4f3126b05b25678b080fbc5c99bced4b52c1 (patch) | |
tree | fe07bd2e49258af7d16384fb9d42d87826458d65 /lvm.c | |
parent | 3fecf187ffda02ff7a18cfb8b0d340e2c0e77310 (diff) | |
download | lua-b5eb4f3126b05b25678b080fbc5c99bced4b52c1.tar.gz lua-b5eb4f3126b05b25678b080fbc5c99bced4b52c1.tar.bz2 lua-b5eb4f3126b05b25678b080fbc5c99bced4b52c1.zip |
small optimization in getglobal
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 38 |
1 files changed, 20 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.37 1999/01/12 18:38:35 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.38 1999/01/13 19:09:04 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 | */ |
@@ -186,30 +186,32 @@ void luaV_rawsettable (TObject *t) { | |||
186 | } | 186 | } |
187 | 187 | ||
188 | 188 | ||
189 | void luaV_getglobal (TaggedString *ts) | 189 | void luaV_getglobal (TaggedString *ts) { |
190 | { | 190 | /* only userdata, tables and nil can have getglobal tag methods */ |
191 | /* WARNING: caller must assure stack space */ | 191 | static char valid_getglobals[] = {1, 0, 0, 1, 0, 0, 1, 0}; /* ORDER LUA_T */ |
192 | TObject *value = &ts->u.s.globalval; | 192 | TObject *value = &ts->u.s.globalval; |
193 | TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL); | 193 | if (valid_getglobals[-ttype(value)]) { |
194 | if (ttype(im) == LUA_T_NIL) { /* default behavior */ | 194 | TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL); |
195 | *L->stack.top++ = *value; | 195 | if (ttype(im) != LUA_T_NIL) { /* is there a tag method? */ |
196 | } | 196 | /* WARNING: caller must assure stack space */ |
197 | else { | 197 | struct Stack *S = &L->stack; |
198 | struct Stack *S = &L->stack; | 198 | ttype(S->top) = LUA_T_STRING; |
199 | ttype(S->top) = LUA_T_STRING; | 199 | tsvalue(S->top) = ts; |
200 | tsvalue(S->top) = ts; | 200 | S->top++; |
201 | S->top++; | 201 | *S->top++ = *value; |
202 | *S->top++ = *value; | 202 | luaD_callTM(im, 2, 1); |
203 | luaD_callTM(im, 2, 1); | 203 | return; |
204 | } | ||
205 | /* else no tag method: go through to default behavior */ | ||
204 | } | 206 | } |
207 | *L->stack.top++ = *value; /* default behavior */ | ||
205 | } | 208 | } |
206 | 209 | ||
207 | 210 | ||
208 | void luaV_setglobal (TaggedString *ts) | 211 | void luaV_setglobal (TaggedString *ts) { |
209 | { | ||
210 | TObject *oldvalue = &ts->u.s.globalval; | 212 | TObject *oldvalue = &ts->u.s.globalval; |
211 | TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL); | 213 | TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL); |
212 | if (ttype(im) == LUA_T_NIL) /* default behavior */ | 214 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ |
213 | luaS_rawsetglobal(ts, --L->stack.top); | 215 | luaS_rawsetglobal(ts, --L->stack.top); |
214 | else { | 216 | else { |
215 | /* WARNING: caller must assure stack space */ | 217 | /* WARNING: caller must assure stack space */ |