commit 9d801f43d47967a533b399352fab63c4a62ffae7
parent e043b72a55493cde9bb9c19997a4d58bac444630
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 10 Dec 2001 20:11:46 -0200
details
Diffstat:
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/ltable.c b/ltable.c
@@ -218,18 +218,17 @@ static void setnodevector (lua_State *L, Table *t, int lsize) {
}
-static void rehash (lua_State *L, Table *t) {
+static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
int i;
- int oldasize, oldhsize, nasize, nhsize;
+ int oldasize, oldhsize;
Node *nold;
- numuse(t, &nasize, &nhsize); /* compute new sizes for array and hash parts */
oldasize = t->sizearray;
if (nasize > oldasize) /* should grow array part? */
setarrayvector(L, t, nasize);
/* create new hash part with appropriate size */
nold = t->node; /* save old hash ... */
oldhsize = t->lsizenode; /* ... and (log of) old size */
- setnodevector(L, t, luaO_log2(nhsize+nhsize/4)+1);
+ setnodevector(L, t, nhsize);
/* re-insert elements */
if (nasize < oldasize) { /* array part must shrink? */
t->sizearray = nasize;
@@ -251,6 +250,16 @@ static void rehash (lua_State *L, Table *t) {
luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
}
+
+static void rehash (lua_State *L, Table *t) {
+ int nasize, nhsize;
+ numuse(t, &nasize, &nhsize); /* compute new sizes for array and hash parts */
+ nhsize += nhsize/4; /* allow some extra for growing nhsize */
+ resize(L, t, nasize, luaO_log2(nhsize)+1);
+}
+
+
+
/*
** }=============================================================
*/