aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-10-25 17:14:14 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-10-25 17:14:14 -0200
commit21aa7e55f2333e57b972aa4ef2c5e2785d609578 (patch)
treebdd6119f0fab0178979202bc5d0afbd6f4410469 /ltests.c
parentfffb6f3814084cddd8a58e81ae1b73ed78ea0953 (diff)
downloadlua-21aa7e55f2333e57b972aa4ef2c5e2785d609578.tar.gz
lua-21aa7e55f2333e57b972aa4ef2c5e2785d609578.tar.bz2
lua-21aa7e55f2333e57b972aa4ef2c5e2785d609578.zip
optimization for array part of a Table
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/ltests.c b/ltests.c
index afcc460a..4b6e3de2 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.92 2001/10/02 16:45:03 roberto Exp $ 2** $Id: ltests.c,v 1.93 2001/10/17 21:12:57 roberto Exp $
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*/
@@ -211,12 +211,6 @@ static int listlocals (lua_State *L) {
211/* }====================================================== */ 211/* }====================================================== */
212 212
213 213
214static int pushbool (lua_State *L, int b) {
215 if (b) lua_pushnumber(L, 1);
216 else lua_pushnil(L);
217 return 1;
218}
219
220 214
221 215
222static int get_limits (lua_State *L) { 216static int get_limits (lua_State *L) {
@@ -252,7 +246,7 @@ static int hash_query (lua_State *L) {
252 } 246 }
253 else { 247 else {
254 TObject *o = luaA_index(L, 1); 248 TObject *o = luaA_index(L, 1);
255 Hash *t; 249 Table *t;
256 luaL_checktype(L, 2, LUA_TTABLE); 250 luaL_checktype(L, 2, LUA_TTABLE);
257 t = hvalue(luaA_index(L, 2)); 251 t = hvalue(luaA_index(L, 2));
258 lua_pushnumber(L, luaH_mainposition(t, o) - t->node); 252 lua_pushnumber(L, luaH_mainposition(t, o) - t->node);
@@ -262,16 +256,21 @@ static int hash_query (lua_State *L) {
262 256
263 257
264static int table_query (lua_State *L) { 258static int table_query (lua_State *L) {
265 const Hash *t; 259 const Table *t;
266 int i = luaL_opt_int(L, 2, -1); 260 int i = luaL_opt_int(L, 2, -1);
267 luaL_checktype(L, 1, LUA_TTABLE); 261 luaL_checktype(L, 1, LUA_TTABLE);
268 t = hvalue(luaA_index(L, 1)); 262 t = hvalue(luaA_index(L, 1));
269 if (i == -1) { 263 if (i == -1) {
270 lua_pushnumber(L, t->size); 264 lua_pushnumber(L, t->sizearray);
265 lua_pushnumber(L, sizenode(t));
271 lua_pushnumber(L, t->firstfree - t->node); 266 lua_pushnumber(L, t->firstfree - t->node);
272 return 2;
273 } 267 }
274 else if (i < t->size) { 268 else if (i < t->sizearray) {
269 lua_pushnumber(L, i);
270 luaA_pushobject(L, &t->array[i]);
271 lua_pushnil(L);
272 }
273 else if ((i -= t->sizearray) < sizenode(t)) {
275 if (ttype(val(node(t, i))) != LUA_TNIL || 274 if (ttype(val(node(t, i))) != LUA_TNIL ||
276 ttype(key(node(t, i))) == LUA_TNIL || 275 ttype(key(node(t, i))) == LUA_TNIL ||
277 ttype(key(node(t, i))) == LUA_TNUMBER) { 276 ttype(key(node(t, i))) == LUA_TNUMBER) {
@@ -280,14 +279,12 @@ static int table_query (lua_State *L) {
280 else 279 else
281 lua_pushstring(L, "<undef>"); 280 lua_pushstring(L, "<undef>");
282 luaA_pushobject(L, &t->node[i].val); 281 luaA_pushobject(L, &t->node[i].val);
283 if (t->node[i].next) { 282 if (t->node[i].next)
284 lua_pushnumber(L, t->node[i].next - t->node); 283 lua_pushnumber(L, t->node[i].next - t->node);
285 return 3;
286 }
287 else 284 else
288 return 2; 285 lua_pushnil(L);
289 } 286 }
290 return 0; 287 return 3;
291} 288}
292 289
293 290
@@ -448,11 +445,12 @@ static int settagmethod (lua_State *L) {
448 return 1; 445 return 1;
449} 446}
450 447
451static int equal (lua_State *L) { 448
452 return pushbool(L, lua_equal(L, 1, 2)); 449static int log2_aux (lua_State *L) {
450 lua_pushnumber(L, luaO_log2(luaL_check_int(L, 1)));
451 return 1;
453} 452}
454 453
455
456 454
457/* 455/*
458** {====================================================== 456** {======================================================
@@ -596,6 +594,13 @@ static int testC (lua_State *L) {
596 else 594 else
597 lua_pushnil(L); 595 lua_pushnil(L);
598 } 596 }
597 else if EQ(l_s("equal")) {
598 int a = getnum;
599 if (lua_equal(L, a, getnum))
600 lua_pushnumber(L, 1);
601 else
602 lua_pushnil(L);
603 }
599 else if EQ(l_s("rawcall")) { 604 else if EQ(l_s("rawcall")) {
600 int narg = getnum; 605 int narg = getnum;
601 int nres = getnum; 606 int nres = getnum;
@@ -656,7 +661,7 @@ static const struct luaL_reg tests_funcs[] = {
656 {l_s("closestate"), closestate}, 661 {l_s("closestate"), closestate},
657 {l_s("doremote"), doremote}, 662 {l_s("doremote"), doremote},
658 {l_s("settagmethod"), settagmethod}, 663 {l_s("settagmethod"), settagmethod},
659 {l_s("equal"), equal}, 664 {l_s("log2"), log2_aux},
660 {l_s("totalmem"), mem_query} 665 {l_s("totalmem"), mem_query}
661}; 666};
662 667