aboutsummaryrefslogtreecommitdiff
path: root/src/lib_table.c
diff options
context:
space:
mode:
authorMike Pall <mike>2013-02-23 02:17:50 +0100
committerMike Pall <mike>2013-02-23 02:17:50 +0100
commit60e380fd936ef45b57e89d8df23ab16325f29e9b (patch)
treee4b60a535833ff6415e252ad228b965e9656a4a2 /src/lib_table.c
parent73ef845fcaf65937ad63e9cf6b681cb3e61f4504 (diff)
downloadluajit-60e380fd936ef45b57e89d8df23ab16325f29e9b.tar.gz
luajit-60e380fd936ef45b57e89d8df23ab16325f29e9b.tar.bz2
luajit-60e380fd936ef45b57e89d8df23ab16325f29e9b.zip
Replace table.getn/foreach/foreachi with bytecode builtins.
Diffstat (limited to 'src/lib_table.c')
-rw-r--r--src/lib_table.c68
1 files changed, 26 insertions, 42 deletions
diff --git a/src/lib_table.c b/src/lib_table.c
index 8d53a6cd..13aff24e 100644
--- a/src/lib_table.c
+++ b/src/lib_table.c
@@ -23,50 +23,34 @@
23 23
24#define LJLIB_MODULE_table 24#define LJLIB_MODULE_table
25 25
26LJLIB_CF(table_foreachi) 26LJLIB_LUA(table_foreachi) /*
27{ 27 function(t, f)
28 GCtab *t = lj_lib_checktab(L, 1); 28 CHECK_tab(t)
29 GCfunc *func = lj_lib_checkfunc(L, 2); 29 CHECK_func(f)
30 MSize i, n = lj_tab_len(t); 30 for i=1,#t do
31 for (i = 1; i <= n; i++) { 31 local r = f(i, t[i])
32 cTValue *val; 32 if r ~= nil then return r end
33 setfuncV(L, L->top, func); 33 end
34 setintV(L->top+1, i); 34 end
35 val = lj_tab_getint(t, (int32_t)i); 35*/
36 if (val) { copyTV(L, L->top+2, val); } else { setnilV(L->top+2); }
37 L->top += 3;
38 lua_call(L, 2, 1);
39 if (!tvisnil(L->top-1))
40 return 1;
41 L->top--;
42 }
43 return 0;
44}
45 36
46LJLIB_CF(table_foreach) 37LJLIB_LUA(table_foreach) /*
47{ 38 function(t, f)
48 GCtab *t = lj_lib_checktab(L, 1); 39 CHECK_tab(t)
49 GCfunc *func = lj_lib_checkfunc(L, 2); 40 CHECK_func(f)
50 L->top = L->base+3; 41 for k, v in PAIRS(t) do
51 setnilV(L->top-1); 42 local r = f(k, v)
52 while (lj_tab_next(L, t, L->top-1)) { 43 if r ~= nil then return r end
53 copyTV(L, L->top+2, L->top); 44 end
54 copyTV(L, L->top+1, L->top-1); 45 end
55 setfuncV(L, L->top, func); 46*/
56 L->top += 3;
57 lua_call(L, 2, 1);
58 if (!tvisnil(L->top-1))
59 return 1;
60 L->top--;
61 }
62 return 0;
63}
64 47
65LJLIB_ASM(table_getn) LJLIB_REC(.) 48LJLIB_LUA(table_getn) /*
66{ 49 function(t)
67 lj_lib_checktab(L, 1); 50 CHECK_tab(t)
68 return FFH_UNREACHABLE; 51 return #t
69} 52 end
53*/
70 54
71LJLIB_CF(table_maxn) 55LJLIB_CF(table_maxn)
72{ 56{