diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-12-10 20:12:08 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-12-10 20:12:08 -0200 |
| commit | 9d801f43d47967a533b399352fab63c4a62ffae7 (patch) | |
| tree | 8826b67b2433b2ce5b62aefed8c2ae022562dab5 | |
| parent | e043b72a55493cde9bb9c19997a4d58bac444630 (diff) | |
| download | lua-9d801f43d47967a533b399352fab63c4a62ffae7.tar.gz lua-9d801f43d47967a533b399352fab63c4a62ffae7.tar.bz2 lua-9d801f43d47967a533b399352fab63c4a62ffae7.zip | |
details
| -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 | */ |
