summaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-01-15 11:14:24 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-01-15 11:14:24 -0200
commitb5eb4f3126b05b25678b080fbc5c99bced4b52c1 (patch)
treefe07bd2e49258af7d16384fb9d42d87826458d65 /lvm.c
parent3fecf187ffda02ff7a18cfb8b0d340e2c0e77310 (diff)
downloadlua-github-b5eb4f3126b05b25678b080fbc5c99bced4b52c1.tar.gz
small optimization in getglobal
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/lvm.c b/lvm.c
index 8f64f9f5..a5b71a5a 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 1.37 1999/01/12 18:38:35 roberto Exp roberto $
+** $Id: lvm.c,v 1.38 1999/01/13 19:09:04 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -186,30 +186,32 @@ void luaV_rawsettable (TObject *t) {
}
-void luaV_getglobal (TaggedString *ts)
-{
- /* WARNING: caller must assure stack space */
+void luaV_getglobal (TaggedString *ts) {
+ /* only userdata, tables and nil can have getglobal tag methods */
+ static char valid_getglobals[] = {1, 0, 0, 1, 0, 0, 1, 0}; /* ORDER LUA_T */
TObject *value = &ts->u.s.globalval;
- TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL);
- if (ttype(im) == LUA_T_NIL) { /* default behavior */
- *L->stack.top++ = *value;
- }
- else {
- struct Stack *S = &L->stack;
- ttype(S->top) = LUA_T_STRING;
- tsvalue(S->top) = ts;
- S->top++;
- *S->top++ = *value;
- luaD_callTM(im, 2, 1);
+ if (valid_getglobals[-ttype(value)]) {
+ TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL);
+ if (ttype(im) != LUA_T_NIL) { /* is there a tag method? */
+ /* WARNING: caller must assure stack space */
+ struct Stack *S = &L->stack;
+ ttype(S->top) = LUA_T_STRING;
+ tsvalue(S->top) = ts;
+ S->top++;
+ *S->top++ = *value;
+ luaD_callTM(im, 2, 1);
+ return;
+ }
+ /* else no tag method: go through to default behavior */
}
+ *L->stack.top++ = *value; /* default behavior */
}
-void luaV_setglobal (TaggedString *ts)
-{
+void luaV_setglobal (TaggedString *ts) {
TObject *oldvalue = &ts->u.s.globalval;
TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL);
- if (ttype(im) == LUA_T_NIL) /* default behavior */
+ if (ttype(im) == LUA_T_NIL) /* is there a tag method? */
luaS_rawsetglobal(ts, --L->stack.top);
else {
/* WARNING: caller must assure stack space */