| 333 | |
| 334 | |
| 335 | void luaH_resize (lua_State *L, Table *t, unsigned int nasize, |
| 336 | unsigned int nhsize) { |
| 337 | unsigned int i; |
| 338 | int j; |
| 339 | unsigned int oldasize = t->sizearray; |
| 340 | int oldhsize = t->lsizenode; |
| 341 | Node *nold = t->node; /* save old hash ... */ |
| 342 | if (nasize > oldasize) /* array part must grow? */ |
| 343 | setarrayvector(L, t, nasize); |
| 344 | /* create new hash part with appropriate size */ |
| 345 | setnodevector(L, t, nhsize); |
| 346 | if (nasize < oldasize) { /* array part must shrink? */ |
| 347 | t->sizearray = nasize; |
| 348 | /* re-insert elements from vanishing slice */ |
| 349 | for (i=nasize; i<oldasize; i++) { |
| 350 | if (!ttisnil(&t->array[i])) |
| 351 | luaH_setint(L, t, i + 1, &t->array[i]); |
| 352 | } |
| 353 | /* shrink array */ |
| 354 | luaM_reallocvector(L, t->array, oldasize, nasize, TValue); |
| 355 | } |
| 356 | /* re-insert elements from hash part */ |
| 357 | for (j = twoto(oldhsize) - 1; j >= 0; j--) { |
| 358 | Node *old = nold + j; |
| 359 | if (!ttisnil(gval(old))) { |
| 360 | /* doesn't need barrier/invalidate cache, as entry was |
| 361 | already present in the table */ |
| 362 | setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old)); |
| 363 | } |
| 364 | } |
| 365 | if (!isdummy(nold)) |
| 366 | luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */ |
| 367 | } |
| 368 | |
| 369 | |
| 370 | void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) { |
no test coverage detected