From cf9a22396c1050f22176fc1367a4e7e2e4e3abc8 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 22 Sep 1999 11:38:45 -0300 Subject: "luaH_set" only needs to check size when key is new --- ltable.c | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) (limited to 'ltable.c') diff --git a/ltable.c b/ltable.c index 53d6c866..fbded6cf 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 1.22 1999/05/21 19:41:49 roberto Exp roberto $ +** $Id: ltable.c,v 1.23 1999/08/16 20:52:00 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -54,8 +54,8 @@ static long int hashindex (const TObject *ref) { Node *luaH_present (const Hash *t, const TObject *key) { - int tsize = nhash(t); - long int h = hashindex(key); + const int tsize = nhash(t); + const long int h = hashindex(key); int h1 = h%tsize; Node *n = node(t, h1); /* keep looking until an entry with "ref" equal to key or nil */ @@ -81,7 +81,7 @@ void luaH_free (Hash *frees) { static Node *hashnodecreate (int nhash) { - Node *v = luaM_newvector(nhash, Node); + Node *const v = luaM_newvector(nhash, Node); int i; for (i=0; inode; - int size = nhash(t); + Node *const v = t->node; + const int size = nhash(t); int realuse = 0; int i; for (i=0; i (long)nhash(t)*2L) { + Node *const n = luaH_present(t, ref); + *val(n) = *val; + if (ttype(ref(n)) == LUA_T_NIL) { /* new node? */ + *ref(n) = *ref; /* set key */ + nuse(t)++; /* count it */ + if ((long)nuse(t)*3L > (long)nhash(t)*2L) /* check size */ rehash(t); - n = luaH_present(t, ref); - } - nuse(t)++; - *ref(n) = *ref; - *val(n) = buff; } } int luaH_pos (const Hash *t, const TObject *r) { - Node *n = luaH_present(t, r); + Node *const n = luaH_present(t, r); luaL_arg_check(ttype(val(n)) != LUA_T_NIL, 2, "key not found"); return n-(t->node); } -- cgit v1.2.3-55-g6feb