aboutsummaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-26 11:18:00 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-26 11:18:00 -0200
commit7959f3aebb5b12f474b65429dedf550b28223e08 (patch)
tree206746f154ef0e211b3ce5f74bf7d9fb241d47c5 /ltable.c
parentbce6572579a7e6c7a96895d9280396b3b33b8f3f (diff)
downloadlua-7959f3aebb5b12f474b65429dedf550b28223e08.tar.gz
lua-7959f3aebb5b12f474b65429dedf550b28223e08.tar.bz2
lua-7959f3aebb5b12f474b65429dedf550b28223e08.zip
easier way to erase 'dead' keys
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c28
1 files changed, 2 insertions, 26 deletions
diff --git a/ltable.c b/ltable.c
index 926fb49e..a13e8c24 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.66 2001/01/24 15:45:33 roberto Exp roberto $ 2** $Id: ltable.c,v 1.67 2001/01/25 16:45:36 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*/
@@ -126,30 +126,6 @@ Node *luaH_next (lua_State *L, const Hash *t, const TObject *key) {
126} 126}
127 127
128 128
129/*
130** try to remove a key without value from a table. To avoid problems with
131** hash, change `key' for a number with the same hash.
132*/
133void luaH_remove (Hash *t, TObject *key) {
134 if (ttype(key) == LUA_TNUMBER ||
135 (ttype(key) == LUA_TSTRING && tsvalue(key)->len <= 30))
136 return; /* do not remove numbers nor small strings */
137 else {
138 /* try to find a number `n' with the same hash as `key' */
139 Node *mp = luaH_mainposition(t, key);
140 int n = mp - &t->node[0];
141 /* make sure `n' is not in `t' */
142 while (luaH_getnum(t, n) != &luaO_nilobject) {
143 if (n >= MAX_INT - t->size)
144 return; /* give up; (to avoid overflow) */
145 n += t->size;
146 }
147 setnvalue(key, n);
148 lua_assert(luaH_mainposition(t, key) == mp);
149 }
150}
151
152
153static void setnodevector (lua_State *L, Hash *t, luint32 size) { 129static void setnodevector (lua_State *L, Hash *t, luint32 size) {
154 int i; 130 int i;
155 if (size > MAX_INT) 131 if (size > MAX_INT)
@@ -227,7 +203,7 @@ static void rehash (lua_State *L, Hash *t) {
227** position), new key goes to an empty position. 203** position), new key goes to an empty position.
228*/ 204*/
229static TObject *newkey (lua_State *L, Hash *t, Node *mp, const TObject *key) { 205static TObject *newkey (lua_State *L, Hash *t, Node *mp, const TObject *key) {
230 if (ttype(&mp->key) != LUA_TNIL) { /* main position is not free? */ 206 if (ttype(&mp->val) != LUA_TNIL) { /* main position is not free? */
231 Node *othern = luaH_mainposition(t, &mp->key); /* `mp' of colliding node */ 207 Node *othern = luaH_mainposition(t, &mp->key); /* `mp' of colliding node */
232 Node *n = t->firstfree; /* get a free place */ 208 Node *n = t->firstfree; /* get a free place */
233 if (othern != mp) { /* is colliding node out of its main position? */ 209 if (othern != mp) { /* is colliding node out of its main position? */