| 467 | |
| 468 | |
| 469 | void luaH_resize(lua_State *L, Table *t, unsigned int nasize, |
| 470 | unsigned int nhsize) { |
| 471 | unsigned int i; |
| 472 | int j; |
| 473 | unsigned int oldasize = t->sizearray; |
| 474 | int oldhsize = t->lsizenode; |
| 475 | Node *nold = t->node; /* save old hash ... */ |
| 476 | if (nasize > oldasize) /* array part must grow? */ |
| 477 | setarrayvector(L, t, nasize); |
| 478 | /* create new hash part with appropriate size */ |
| 479 | setnodevector(L, t, nhsize); |
| 480 | if (nasize < oldasize) { /* array part must shrink? */ |
| 481 | t->sizearray = nasize; |
| 482 | /* re-insert elements from vanishing slice */ |
| 483 | for (i = nasize; i < oldasize; i++) { |
| 484 | if (!ttisnil(&t->array[i])) |
| 485 | luaH_setint(L, t, i + 1, &t->array[i]); |
| 486 | } |
| 487 | /* shrink array */ |
| 488 | luaM_reallocvector(L, t->array, oldasize, nasize, TValue); |
| 489 | } |
| 490 | /* re-insert elements from hash part */ |
| 491 | for (j = twoto(oldhsize) - 1; j >= 0; j--) { |
| 492 | Node *old = nold + j; |
| 493 | if (!ttisnil(gval(old))) { |
| 494 | /* doesn't need barrier/invalidate cache, as entry was |
| 495 | already present in the table */ |
| 496 | setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old)); |
| 497 | } |
| 498 | } |
| 499 | if (!isdummy(nold)) |
| 500 | luaM_freearray(L, nold, lua_cast(size_t, twoto(oldhsize))); /* free old hash */ |
| 501 | } |
| 502 | |
| 503 | |
| 504 | void luaH_resizearray(lua_State *L, Table *t, unsigned int nasize) { |
no test coverage detected