diff options
author | Mike Pall <mike> | 2013-02-24 17:59:04 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2013-02-24 17:59:04 +0100 |
commit | 5e601891fc9faf8cde836e6515bfdd273dd113e9 (patch) | |
tree | 2fbf828cd0fc714fe902f8ba81b20b09769247f9 /src/lib_table.c | |
parent | b8abb4b91d006f884c81b9e95484373bd6eed2d9 (diff) | |
download | luajit-5e601891fc9faf8cde836e6515bfdd273dd113e9.tar.gz luajit-5e601891fc9faf8cde836e6515bfdd273dd113e9.tar.bz2 luajit-5e601891fc9faf8cde836e6515bfdd273dd113e9.zip |
Replace table.remove with bytecode builtin.
Diffstat (limited to 'src/lib_table.c')
-rw-r--r-- | src/lib_table.c | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/lib_table.c b/src/lib_table.c index 13aff24e..89884f77 100644 --- a/src/lib_table.c +++ b/src/lib_table.c | |||
@@ -103,27 +103,29 @@ LJLIB_CF(table_insert) LJLIB_REC(.) | |||
103 | return 0; | 103 | return 0; |
104 | } | 104 | } |
105 | 105 | ||
106 | LJLIB_CF(table_remove) LJLIB_REC(.) | 106 | LJLIB_LUA(table_remove) /* |
107 | { | 107 | function(t, pos) |
108 | GCtab *t = lj_lib_checktab(L, 1); | 108 | CHECK_tab(t) |
109 | int32_t e = (int32_t)lj_tab_len(t); | 109 | local len = #t |
110 | int32_t pos = lj_lib_optint(L, 2, e); | 110 | if pos == nil then |
111 | if (!(1 <= pos && pos <= e)) /* Nothing to remove? */ | 111 | if len ~= 0 then |
112 | return 0; | 112 | local old = t[len] |
113 | lua_rawgeti(L, 1, pos); /* Get previous value. */ | 113 | t[len] = nil |
114 | /* NOBARRIER: This just moves existing elements around. */ | 114 | return old |
115 | for (; pos < e; pos++) { | 115 | end |
116 | cTValue *src = lj_tab_getint(t, pos+1); | 116 | else |
117 | TValue *dst = lj_tab_setint(L, t, pos); | 117 | CHECK_int(pos) |
118 | if (src) { | 118 | if pos >= 1 and pos <= len then |
119 | copyTV(L, dst, src); | 119 | local old = t[pos] |
120 | } else { | 120 | for i=pos+1,len do |
121 | setnilV(dst); | 121 | t[i-1] = t[i] |
122 | } | 122 | end |
123 | } | 123 | t[len] = nil |
124 | setnilV(lj_tab_setint(L, t, e)); /* Remove (last) value. */ | 124 | return old |
125 | return 1; /* Return previous value. */ | 125 | end |
126 | } | 126 | end |
127 | end | ||
128 | */ | ||
127 | 129 | ||
128 | LJLIB_CF(table_concat) | 130 | LJLIB_CF(table_concat) |
129 | { | 131 | { |