diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-08-30 17:56:43 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-08-30 17:56:43 -0300 |
commit | 8c8ad5f3fffae16a751f2419a5972ec7ffd6babf (patch) | |
tree | db9e7977a263eb91b4c990420af203ce0d4f7d2a /lvm.c | |
parent | 34a09b65f3b6ef5f7699263b09ad088ec087aca2 (diff) | |
download | lua-8c8ad5f3fffae16a751f2419a5972ec7ffd6babf.tar.gz lua-8c8ad5f3fffae16a751f2419a5972ec7ffd6babf.tar.bz2 lua-8c8ad5f3fffae16a751f2419a5972ec7ffd6babf.zip |
better locality of assignment of table values
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.189 2001/06/28 14:48:44 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.190 2001/06/28 14:57:17 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,7 +186,7 @@ void luaV_settable (lua_State *L, StkId t, TObject *key, StkId val) { | |||
186 | int tg = hvalue(t)->htag; | 186 | int tg = hvalue(t)->htag; |
187 | if (hvalue(t)->htag == LUA_TTABLE || /* with default tag? */ | 187 | if (hvalue(t)->htag == LUA_TTABLE || /* with default tag? */ |
188 | (tm = luaT_gettm(G(L), tg, TM_SETTABLE)) == NULL) { /* or no TM? */ | 188 | (tm = luaT_gettm(G(L), tg, TM_SETTABLE)) == NULL) { /* or no TM? */ |
189 | setobj(luaH_set(L, hvalue(t), key), val); /* do a primitive set */ | 189 | luaH_set(L, hvalue(t), key, val); /* do a primitive set */ |
190 | return; | 190 | return; |
191 | } | 191 | } |
192 | /* else will call the tag method */ | 192 | /* else will call the tag method */ |
@@ -212,11 +212,14 @@ void luaV_getglobal (lua_State *L, TString *name, StkId res) { | |||
212 | 212 | ||
213 | 213 | ||
214 | void luaV_setglobal (lua_State *L, TString *name, StkId val) { | 214 | void luaV_setglobal (lua_State *L, TString *name, StkId val) { |
215 | TObject *oldvalue = luaH_setstr(L, L->gt, name); | 215 | const TObject *oldvalue = luaH_getstr(L->gt, name); |
216 | Closure *tm; | 216 | Closure *tm; |
217 | if (!HAS_TM_SETGLOBAL(L, ttype(oldvalue)) || /* no tag methods? */ | 217 | if (!HAS_TM_SETGLOBAL(L, ttype(oldvalue)) || /* no tag methods? */ |
218 | (tm = luaT_gettmbyObj(G(L), oldvalue, TM_SETGLOBAL)) == NULL) { | 218 | (tm = luaT_gettmbyObj(G(L), oldvalue, TM_SETGLOBAL)) == NULL) { |
219 | setobj(oldvalue, val); /* raw set */ | 219 | if (oldvalue == &luaO_nilobject) |
220 | luaH_setstr(L, L->gt, name, val); /* raw set */ | ||
221 | else | ||
222 | settableval(oldvalue, val); /* warning: tricky optimization! */ | ||
220 | } | 223 | } |
221 | else | 224 | else |
222 | setTM(L, callTM(L, tm, l_s("soo"), name, oldvalue, val)); | 225 | setTM(L, callTM(L, tm, l_s("soo"), name, oldvalue, val)); |
@@ -317,12 +320,12 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
317 | static void luaV_pack (lua_State *L, StkId firstelem) { | 320 | static void luaV_pack (lua_State *L, StkId firstelem) { |
318 | int i; | 321 | int i; |
319 | Hash *htab = luaH_new(L, 0); | 322 | Hash *htab = luaH_new(L, 0); |
320 | TObject *n; | 323 | TObject n; |
321 | for (i=0; firstelem+i<L->top; i++) | 324 | for (i=0; firstelem+i<L->top; i++) |
322 | setobj(luaH_setnum(L, htab, i+1), firstelem+i); | 325 | luaH_setnum(L, htab, i+1, firstelem+i); |
323 | /* store counter in field `n' */ | 326 | /* store counter in field `n' */ |
324 | n = luaH_setstr(L, htab, luaS_newliteral(L, l_s("n"))); | 327 | setnvalue(&n, i); |
325 | setnvalue(n, i); | 328 | luaH_setstr(L, htab, luaS_newliteral(L, l_s("n")), &n); |
326 | L->top = firstelem; /* remove elements from the stack */ | 329 | L->top = firstelem; /* remove elements from the stack */ |
327 | sethvalue(L->top, htab); | 330 | sethvalue(L->top, htab); |
328 | incr_top; | 331 | incr_top; |
@@ -640,7 +643,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
640 | n = L->top - ra - 1; | 643 | n = L->top - ra - 1; |
641 | bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ | 644 | bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ |
642 | for (; n > 0; n--) | 645 | for (; n > 0; n--) |
643 | setobj(luaH_setnum(L, h, bc+n), ra+n); | 646 | luaH_setnum(L, h, bc+n, ra+n); |
644 | break; | 647 | break; |
645 | } | 648 | } |
646 | case OP_CLOSURE: { | 649 | case OP_CLOSURE: { |