summaryrefslogtreecommitdiff
path: root/src/lib_table.c
diff options
context:
space:
mode:
authorMike Pall <mike>2009-12-08 19:49:20 +0100
committerMike Pall <mike>2009-12-08 19:49:20 +0100
commit1d1fed48a002dfc0919135911057ebc255a53e0a (patch)
treec5c6643908374bb8f02f4c7691332d32f6645986 /src/lib_table.c
parent55b16959717084884fd4a0cbae6d19e3786c20c7 (diff)
downloadluajit-1d1fed48a002dfc0919135911057ebc255a53e0a.tar.gz
luajit-1d1fed48a002dfc0919135911057ebc255a53e0a.tar.bz2
luajit-1d1fed48a002dfc0919135911057ebc255a53e0a.zip
RELEASE LuaJIT-2.0.0-beta2v2.0.0-beta2
Diffstat (limited to 'src/lib_table.c')
-rw-r--r--src/lib_table.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/lib_table.c b/src/lib_table.c
index 68dc825b..df9007c8 100644
--- a/src/lib_table.c
+++ b/src/lib_table.c
@@ -74,21 +74,21 @@ LJLIB_CF(table_maxn)
74 TValue *array = tvref(t->array); 74 TValue *array = tvref(t->array);
75 Node *node; 75 Node *node;
76 lua_Number m = 0; 76 lua_Number m = 0;
77 uint32_t i; 77 ptrdiff_t i;
78 for (i = 0; i < t->asize; i++) 78 for (i = (ptrdiff_t)t->asize - 1; i >= 0; i--)
79 if (!tvisnil(&array[i])) { 79 if (!tvisnil(&array[i])) {
80 m = (lua_Number)i; 80 m = (lua_Number)(int32_t)i;
81 break; 81 break;
82 } 82 }
83 node = noderef(t->node); 83 node = noderef(t->node);
84 for (i = 0; i <= t->hmask; i++) 84 for (i = (ptrdiff_t)t->hmask; i >= 0; i--)
85 if (tvisnum(&node[i].key) && numV(&node[i].key) > m) 85 if (tvisnum(&node[i].key) && numV(&node[i].key) > m)
86 m = numV(&node[i].key); 86 m = numV(&node[i].key);
87 setnumV(L->top-1, m); 87 setnumV(L->top-1, m);
88 return 1; 88 return 1;
89} 89}
90 90
91LJLIB_CF(table_insert) 91LJLIB_CF(table_insert) LJLIB_REC(.)
92{ 92{
93 GCtab *t = lj_lib_checktab(L, 1); 93 GCtab *t = lj_lib_checktab(L, 1);
94 int32_t n, i = (int32_t)lj_tab_len(t) + 1; 94 int32_t n, i = (int32_t)lj_tab_len(t) + 1;
@@ -111,20 +111,20 @@ LJLIB_CF(table_insert)
111 } 111 }
112 { 112 {
113 TValue *dst = lj_tab_setint(L, t, i); 113 TValue *dst = lj_tab_setint(L, t, i);
114 copyTV(L, dst, L->top-1); 114 copyTV(L, dst, L->top-1); /* Set new value. */
115 lj_gc_barriert(L, t, dst); 115 lj_gc_barriert(L, t, dst);
116 } 116 }
117 return 0; 117 return 0;
118} 118}
119 119
120LJLIB_CF(table_remove) 120LJLIB_CF(table_remove) LJLIB_REC(.)
121{ 121{
122 GCtab *t = lj_lib_checktab(L, 1); 122 GCtab *t = lj_lib_checktab(L, 1);
123 int32_t e = (int32_t)lj_tab_len(t); 123 int32_t e = (int32_t)lj_tab_len(t);
124 int32_t pos = lj_lib_optint(L, 2, e); 124 int32_t pos = lj_lib_optint(L, 2, e);
125 if (!(1 <= pos && pos <= e)) /* position is outside bounds? */ 125 if (!(1 <= pos && pos <= e)) /* Nothing to remove? */
126 return 0; /* nothing to remove */ 126 return 0;
127 lua_rawgeti(L, 1, pos); 127 lua_rawgeti(L, 1, pos); /* Get previous value. */
128 /* NOBARRIER: This just moves existing elements around. */ 128 /* NOBARRIER: This just moves existing elements around. */
129 for (; pos < e; pos++) { 129 for (; pos < e; pos++) {
130 cTValue *src = lj_tab_getint(t, pos+1); 130 cTValue *src = lj_tab_getint(t, pos+1);
@@ -135,8 +135,8 @@ LJLIB_CF(table_remove)
135 setnilV(dst); 135 setnilV(dst);
136 } 136 }
137 } 137 }
138 setnilV(lj_tab_setint(L, t, e)); 138 setnilV(lj_tab_setint(L, t, e)); /* Remove (last) value. */
139 return 1; 139 return 1; /* Return previous value. */
140} 140}
141 141
142LJLIB_CF(table_concat) 142LJLIB_CF(table_concat)