From 9d801f43d47967a533b399352fab63c4a62ffae7 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 10 Dec 2001 20:12:08 -0200 Subject: details --- ltable.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'ltable.c') diff --git a/ltable.c b/ltable.c index 25d62e41..06e42a79 100644 --- 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); +} + + + /* ** }============================================================= */ -- cgit v1.2.3-55-g6feb