diff options
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -218,18 +218,17 @@ static void setnodevector (lua_State *L, Table *t, int lsize) { | |||
218 | } | 218 | } |
219 | 219 | ||
220 | 220 | ||
221 | static void rehash (lua_State *L, Table *t) { | 221 | static void resize (lua_State *L, Table *t, int nasize, int nhsize) { |
222 | int i; | 222 | int i; |
223 | int oldasize, oldhsize, nasize, nhsize; | 223 | int oldasize, oldhsize; |
224 | Node *nold; | 224 | Node *nold; |
225 | numuse(t, &nasize, &nhsize); /* compute new sizes for array and hash parts */ | ||
226 | oldasize = t->sizearray; | 225 | oldasize = t->sizearray; |
227 | if (nasize > oldasize) /* should grow array part? */ | 226 | if (nasize > oldasize) /* should grow array part? */ |
228 | setarrayvector(L, t, nasize); | 227 | setarrayvector(L, t, nasize); |
229 | /* create new hash part with appropriate size */ | 228 | /* create new hash part with appropriate size */ |
230 | nold = t->node; /* save old hash ... */ | 229 | nold = t->node; /* save old hash ... */ |
231 | oldhsize = t->lsizenode; /* ... and (log of) old size */ | 230 | oldhsize = t->lsizenode; /* ... and (log of) old size */ |
232 | setnodevector(L, t, luaO_log2(nhsize+nhsize/4)+1); | 231 | setnodevector(L, t, nhsize); |
233 | /* re-insert elements */ | 232 | /* re-insert elements */ |
234 | if (nasize < oldasize) { /* array part must shrink? */ | 233 | if (nasize < oldasize) { /* array part must shrink? */ |
235 | t->sizearray = nasize; | 234 | t->sizearray = nasize; |
@@ -251,6 +250,16 @@ static void rehash (lua_State *L, Table *t) { | |||
251 | luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ | 250 | luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ |
252 | } | 251 | } |
253 | 252 | ||
253 | |||
254 | static void rehash (lua_State *L, Table *t) { | ||
255 | int nasize, nhsize; | ||
256 | numuse(t, &nasize, &nhsize); /* compute new sizes for array and hash parts */ | ||
257 | nhsize += nhsize/4; /* allow some extra for growing nhsize */ | ||
258 | resize(L, t, nasize, luaO_log2(nhsize)+1); | ||
259 | } | ||
260 | |||
261 | |||
262 | |||
254 | /* | 263 | /* |
255 | ** }============================================================= | 264 | ** }============================================================= |
256 | */ | 265 | */ |