aboutsummaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-07 17:21:34 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-07 17:21:34 -0300
commitd9e61e8ceafe8c3f6ad936979719ca7c446ce228 (patch)
tree0808ada3d7b7219022b9002503894c76c7253df6 /ltable.c
parent397905ef8694ec716a51acebc993bb625340d388 (diff)
downloadlua-d9e61e8ceafe8c3f6ad936979719ca7c446ce228.tar.gz
lua-d9e61e8ceafe8c3f6ad936979719ca7c446ce228.tar.bz2
lua-d9e61e8ceafe8c3f6ad936979719ca7c446ce228.zip
new algorithm for traversing in GC to avoid deep recursion calls
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/ltable.c b/ltable.c
index d91ed36c..fefd4043 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.50 2000/06/30 14:35:17 roberto Exp roberto $ 2** $Id: ltable.c,v 1.51 2000/08/04 19:38:35 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -127,14 +127,16 @@ int luaH_pos (lua_State *L, const Hash *t, const TObject *key) {
127** hash, change `key' for a number with the same hash. 127** hash, change `key' for a number with the same hash.
128*/ 128*/
129void luaH_remove (Hash *t, TObject *key) { 129void luaH_remove (Hash *t, TObject *key) {
130 /* do not remove numbers */ 130 if (ttype(key) == TAG_NUMBER ||
131 if (ttype(key) != TAG_NUMBER) { 131 (ttype(key) == TAG_STRING && tsvalue(key)->u.s.len <= 30))
132 return; /* do not remove numbers nor small strings */
133 else {
132 /* try to find a number `n' with the same hash as `key' */ 134 /* try to find a number `n' with the same hash as `key' */
133 Node *mp = luaH_mainposition(t, key); 135 Node *mp = luaH_mainposition(t, key);
134 int n = mp - &t->node[0]; 136 int n = mp - &t->node[0];
135 /* make sure `n' is not in `t' */ 137 /* make sure `n' is not in `t' */
136 while (luaH_getnum(t, n) != &luaO_nilobject) { 138 while (luaH_getnum(t, n) != &luaO_nilobject) {
137 if (t->size >= MAX_INT-n) 139 if (n >= MAX_INT - t->size)
138 return; /* give up; (to avoid overflow) */ 140 return; /* give up; (to avoid overflow) */
139 n += t->size; 141 n += t->size;
140 } 142 }
@@ -165,7 +167,7 @@ Hash *luaH_new (lua_State *L, int size) {
165 t->htag = TagDefault; 167 t->htag = TagDefault;
166 t->next = L->roottable; 168 t->next = L->roottable;
167 L->roottable = t; 169 L->roottable = t;
168 t->marked = 0; 170 t->mark = t;
169 t->size = 0; 171 t->size = 0;
170 L->nblocks += gcsize(L, 0); 172 L->nblocks += gcsize(L, 0);
171 t->node = NULL; 173 t->node = NULL;