diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-18 13:02:56 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-18 13:02:56 -0300 |
commit | 60c83ded3080a23bc661ab440c36d0a71b399e2e (patch) | |
tree | 0aa24b14c1215541b52e7885fd2f2c41aa128a06 | |
parent | 07948c3181702c55b7b36069ca519b54371a4ab7 (diff) | |
download | lua-60c83ded3080a23bc661ab440c36d0a71b399e2e.tar.gz lua-60c83ded3080a23bc661ab440c36d0a71b399e2e.tar.bz2 lua-60c83ded3080a23bc661ab440c36d0a71b399e2e.zip |
small optimization for sizes of array constructors
-rw-r--r-- | lobject.c | 16 | ||||
-rw-r--r-- | lobject.h | 5 | ||||
-rw-r--r-- | lparser.c | 5 | ||||
-rw-r--r-- | ltests.c | 10 | ||||
-rw-r--r-- | lvm.c | 4 |
5 files changed, 31 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 1.94 2002/12/04 17:38:31 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.95 2003/01/27 13:00:43 roberto Exp roberto $ |
3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -30,6 +30,20 @@ | |||
30 | const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; | 30 | const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; |
31 | 31 | ||
32 | 32 | ||
33 | /* | ||
34 | ** converts an integer to a "floating point byte", represented as | ||
35 | ** (mmmmmxxx), where the real value is (xxx) * 2^(mmmmm) | ||
36 | */ | ||
37 | int luaO_int2fb (unsigned int x) { | ||
38 | int m = 0; /* mantissa */ | ||
39 | while (x >= (1<<3)) { | ||
40 | x = (x+1) >> 1; | ||
41 | m++; | ||
42 | } | ||
43 | return (m << 3) | cast(int, x); | ||
44 | } | ||
45 | |||
46 | |||
33 | int luaO_log2 (unsigned int x) { | 47 | int luaO_log2 (unsigned int x) { |
34 | static const lu_byte log_8[255] = { | 48 | static const lu_byte log_8[255] = { |
35 | 0, | 49 | 0, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.156 2002/12/19 11:11:55 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.157 2003/02/11 10:46:24 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -323,7 +323,8 @@ typedef struct Table { | |||
323 | extern const TObject luaO_nilobject; | 323 | extern const TObject luaO_nilobject; |
324 | 324 | ||
325 | int luaO_log2 (unsigned int x); | 325 | int luaO_log2 (unsigned int x); |
326 | 326 | int luaO_int2fb (unsigned int x); | |
327 | #define fb2int(x) (((x) & 7) << ((x) >> 3)) | ||
327 | 328 | ||
328 | int luaO_rawequalObj (const TObject *t1, const TObject *t2); | 329 | int luaO_rawequalObj (const TObject *t1, const TObject *t2); |
329 | int luaO_str2d (const char *s, lua_Number *result); | 330 | int luaO_str2d (const char *s, lua_Number *result); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.204 2003/02/11 10:46:24 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.205 2003/02/11 10:49:53 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -515,8 +515,7 @@ static void constructor (LexState *ls, expdesc *t) { | |||
515 | } while (testnext(ls, ',') || testnext(ls, ';')); | 515 | } while (testnext(ls, ',') || testnext(ls, ';')); |
516 | check_match(ls, '}', '{', line); | 516 | check_match(ls, '}', '{', line); |
517 | lastlistfield(fs, &cc); | 517 | lastlistfield(fs, &cc); |
518 | if (cc.na > 0) | 518 | SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */ |
519 | SETARG_B(fs->f->code[pc], luaO_log2(cc.na-1)+2); /* set initial table size */ | ||
520 | SETARG_C(fs->f->code[pc], luaO_log2(cc.nh)+1); /* set initial table size */ | 519 | SETARG_C(fs->f->code[pc], luaO_log2(cc.nh)+1); /* set initial table size */ |
521 | } | 520 | } |
522 | 521 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.151 2003/01/29 10:27:53 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.152 2003/02/10 17:31:13 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -512,6 +512,13 @@ static int log2_aux (lua_State *L) { | |||
512 | return 1; | 512 | return 1; |
513 | } | 513 | } |
514 | 514 | ||
515 | static int int2fb_aux (lua_State *L) { | ||
516 | int b = luaO_int2fb(luaL_checkint(L, 1)); | ||
517 | lua_pushnumber(L, b); | ||
518 | lua_pushnumber(L, fb2int(b)); | ||
519 | return 2; | ||
520 | } | ||
521 | |||
515 | 522 | ||
516 | static int test_do (lua_State *L) { | 523 | static int test_do (lua_State *L) { |
517 | const char *p = luaL_checkstring(L, 1); | 524 | const char *p = luaL_checkstring(L, 1); |
@@ -790,6 +797,7 @@ static const struct luaL_reg tests_funcs[] = { | |||
790 | {"closestate", closestate}, | 797 | {"closestate", closestate}, |
791 | {"doremote", doremote}, | 798 | {"doremote", doremote}, |
792 | {"log2", log2_aux}, | 799 | {"log2", log2_aux}, |
800 | {"int2fb", int2fb_aux}, | ||
793 | {"totalmem", mem_query}, | 801 | {"totalmem", mem_query}, |
794 | {"resume", coresume}, | 802 | {"resume", coresume}, |
795 | {"setyhook", setyhook}, | 803 | {"setyhook", setyhook}, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.274 2003/01/27 15:12:52 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.275 2003/02/11 10:46:24 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 | */ |
@@ -495,7 +495,7 @@ StkId luaV_execute (lua_State *L) { | |||
495 | } | 495 | } |
496 | case OP_NEWTABLE: { | 496 | case OP_NEWTABLE: { |
497 | int b = GETARG_B(i); | 497 | int b = GETARG_B(i); |
498 | if (b > 0) b = twoto(b-1); | 498 | b = fb2int(b); |
499 | sethvalue(ra, luaH_new(L, b, GETARG_C(i))); | 499 | sethvalue(ra, luaH_new(L, b, GETARG_C(i))); |
500 | luaC_checkGC(L); | 500 | luaC_checkGC(L); |
501 | break; | 501 | break; |