aboutsummaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-08-10 18:36:32 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-08-10 18:36:32 -0300
commit5378331f2df1ba5bc3a4dc38f7b3ae53c3f2cbef (patch)
treea6812bd7389ac65f84572a4b65e1a767c5b7499a /ltable.c
parent894a2646719006489800ea68b0515ab956f8aa62 (diff)
downloadlua-5378331f2df1ba5bc3a4dc38f7b3ae53c3f2cbef.tar.gz
lua-5378331f2df1ba5bc3a4dc38f7b3ae53c3f2cbef.tar.bz2
lua-5378331f2df1ba5bc3a4dc38f7b3ae53c3f2cbef.zip
hash tables may shrink if use rate is too small.
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/ltable.c b/ltable.c
index 91556b78..ac0c6a94 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.12 1998/01/28 16:50:33 roberto Exp roberto $ 2** $Id: ltable.c,v 1.13 1998/07/12 16:15:19 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*/
@@ -121,8 +121,7 @@ Hash *luaH_new (int nhash)
121} 121}
122 122
123 123
124static int newsize (Hash *t) 124static int newsize (Hash *t) {
125{
126 Node *v = t->node; 125 Node *v = t->node;
127 int size = nhash(t); 126 int size = nhash(t);
128 int realuse = 0; 127 int realuse = 0;
@@ -131,10 +130,7 @@ static int newsize (Hash *t)
131 if (ttype(ref(v+i)) != LUA_T_NIL && ttype(val(v+i)) != LUA_T_NIL) 130 if (ttype(ref(v+i)) != LUA_T_NIL && ttype(val(v+i)) != LUA_T_NIL)
132 realuse++; 131 realuse++;
133 } 132 }
134 if (2*(realuse+1) <= size) /* +1 is the new element */ 133 return luaO_redimension((realuse+1)*2); /* +1 is the new element */
135 return size; /* don't need to grow, just rehash */
136 else
137 return luaO_redimension(size);
138} 134}
139 135
140static void rehash (Hash *t) 136static void rehash (Hash *t)