diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-10-25 17:14:14 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-10-25 17:14:14 -0200 |
commit | 21aa7e55f2333e57b972aa4ef2c5e2785d609578 (patch) | |
tree | bdd6119f0fab0178979202bc5d0afbd6f4410469 /lvm.c | |
parent | fffb6f3814084cddd8a58e81ae1b73ed78ea0953 (diff) | |
download | lua-21aa7e55f2333e57b972aa4ef2c5e2785d609578.tar.gz lua-21aa7e55f2333e57b972aa4ef2c5e2785d609578.tar.bz2 lua-21aa7e55f2333e57b972aa4ef2c5e2785d609578.zip |
optimization for array part of a Table
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.193 2001/09/07 17:39:10 roberto Exp $ | 2 | ** $Id: lvm.c,v 1.195 2001/10/02 16:45:03 roberto Exp $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -295,7 +295,7 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
295 | 295 | ||
296 | static void luaV_pack (lua_State *L, StkId firstelem) { | 296 | static void luaV_pack (lua_State *L, StkId firstelem) { |
297 | int i; | 297 | int i; |
298 | Hash *htab = luaH_new(L, 0); | 298 | Table *htab = luaH_new(L, 0, 0); |
299 | TObject n; | 299 | TObject n; |
300 | for (i=0; firstelem+i<L->top; i++) | 300 | for (i=0; firstelem+i<L->top; i++) |
301 | luaH_setnum(L, htab, i+1, firstelem+i); | 301 | luaH_setnum(L, htab, i+1, firstelem+i); |
@@ -420,7 +420,9 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
420 | break; | 420 | break; |
421 | } | 421 | } |
422 | case OP_NEWTABLE: { | 422 | case OP_NEWTABLE: { |
423 | sethvalue(ra, luaH_new(L, GETARG_Bc(i))); | 423 | int b = GETARG_B(i); |
424 | if (b > 0) b = twoto(b-1); | ||
425 | sethvalue(ra, luaH_new(L, b, GETARG_C(i))); | ||
424 | luaV_checkGC(L, ra+1); | 426 | luaV_checkGC(L, ra+1); |
425 | break; | 427 | break; |
426 | } | 428 | } |
@@ -599,18 +601,15 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
599 | /* go through */ | 601 | /* go through */ |
600 | } | 602 | } |
601 | case OP_TFORLOOP: { | 603 | case OP_TFORLOOP: { |
602 | Hash *t; | 604 | Table *t; |
603 | int n; | 605 | int n; |
604 | runtime_check(L, ttype(ra) == LUA_TTABLE && | 606 | runtime_check(L, ttype(ra) == LUA_TTABLE && |
605 | ttype(ra+1) == LUA_TNUMBER); | 607 | ttype(ra+1) == LUA_TNUMBER); |
606 | t = hvalue(ra); | 608 | t = hvalue(ra); |
607 | n = cast(int, nvalue(ra+1)); | 609 | n = cast(int, nvalue(ra+1)); |
608 | n = luaH_nexti(t, n); | 610 | n = luaH_nexti(t, n, ra+2); |
609 | if (n != -1) { /* repeat loop? */ | 611 | if (n != -1) { /* repeat loop? */ |
610 | Node *node = node(t, n); | ||
611 | setnvalue(ra+1, n); /* index */ | 612 | setnvalue(ra+1, n); /* index */ |
612 | setobj(ra+2, key(node)); | ||
613 | setobj(ra+3, val(node)); | ||
614 | dojump(pc, i); /* repeat loop */ | 613 | dojump(pc, i); /* repeat loop */ |
615 | } | 614 | } |
616 | break; | 615 | break; |
@@ -619,7 +618,7 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
619 | case OP_SETLISTO: { | 618 | case OP_SETLISTO: { |
620 | int bc; | 619 | int bc; |
621 | int n; | 620 | int n; |
622 | Hash *h; | 621 | Table *h; |
623 | runtime_check(L, ttype(ra) == LUA_TTABLE); | 622 | runtime_check(L, ttype(ra) == LUA_TTABLE); |
624 | h = hvalue(ra); | 623 | h = hvalue(ra); |
625 | bc = GETARG_Bc(i); | 624 | bc = GETARG_Bc(i); |