From 1b45e967b4dcb234551c2a731147b111584f4145 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 25 Jan 1999 10:30:11 -0200 Subject: table entries with ref=null always have val=null too. --- ltable.c | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'ltable.c') diff --git a/ltable.c b/ltable.c index 205ab574..3363be88 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 1.17 1999/01/04 12:54:33 roberto Exp $ +** $Id: ltable.c,v 1.18 1999/01/22 18:47:23 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -53,20 +53,20 @@ static long int hashindex (TObject *ref) { } -static Node *present (Hash *t, TObject *key) { +Node *luaH_present (Hash *t, TObject *ref) { int tsize = nhash(t); - long int h = hashindex(key); + long int h = hashindex(ref); int h1 = h%tsize; Node *n = node(t, h1); - /* keep looking until an entry with "ref" equal to key or nil */ - if ((ttype(ref(n)) == ttype(key) ? !luaO_equalval(key, ref(n)) + /* keep looking until an entry with "ref" equal to ref or nil */ + if ((ttype(ref(n)) == ttype(ref) ? !luaO_equalval(ref, ref(n)) : ttype(ref(n)) != LUA_T_NIL)) { int h2 = h%(tsize-2) + 1; do { h1 += h2; if (h1 >= tsize) h1 -= tsize; n = node(t, h1); - } while ((ttype(ref(n)) == ttype(key) ? !luaO_equalval(key, ref(n)) + } while ((ttype(ref(n)) == ttype(ref) ? !luaO_equalval(ref, ref(n)) : ttype(ref(n)) != LUA_T_NIL)); } return n; @@ -88,7 +88,7 @@ static Node *hashnodecreate (int nhash) { Node *v = luaM_newvector(nhash, Node); int i; for (i=0; i (long)nhash(t)*2L) { rehash(t); - n = present(t, ref); + n = luaH_present(t, ref); } nuse(t)++; *ref(n) = *ref; - ttype(val(n)) = LUA_T_NIL; } return (val(n)); } @@ -175,7 +163,7 @@ static Node *hashnext (Hash *t, int i) { if (i >= tsize) return NULL; n = node(t, i); - while (ttype(ref(n)) == LUA_T_NIL || ttype(val(n)) == LUA_T_NIL) { + while (ttype(val(n)) == LUA_T_NIL) { if (++i >= tsize) return NULL; n = node(t, i); @@ -187,9 +175,8 @@ Node *luaH_next (Hash *t, TObject *r) { if (ttype(r) == LUA_T_NIL) return hashnext(t, 0); else { - Node *n = present(t, r); - luaL_arg_check(ttype(ref(n))!=LUA_T_NIL && ttype(val(n))!=LUA_T_NIL, - 2, "key not found"); + Node *n = luaH_present(t, r); + luaL_arg_check(ttype(val(n)) != LUA_T_NIL, 2, "key not found"); return hashnext(t, (n-(t->node))+1); } } -- cgit v1.2.3-55-g6feb