** Traverse a table with weak values and link it to proper list. During ** propagate phase, keep it in 'grayagain' list, to be revisited in the ** atomic phase. In the atomic phase, if table has any white value, ** put it in 'weak' list, to be cleared. */
| 444 | ** put it in 'weak' list, to be cleared. |
| 445 | */ |
| 446 | static void traverseweakvalue (global_State *g, Table *h) { |
| 447 | Node *n, *limit = gnodelast(h); |
| 448 | /* if there is array part, assume it may have white values (it is not |
| 449 | worth traversing it now just to check) */ |
| 450 | int hasclears = (h->alimit > 0); |
| 451 | for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */ |
| 452 | if (isempty(gval(n))) /* entry is empty? */ |
| 453 | clearkey(n); /* clear its key */ |
| 454 | else { |
| 455 | lua_assert(!keyisnil(n)); |
| 456 | markkey(g, n); |
| 457 | if (!hasclears && iscleared(g, gcvalueN(gval(n)))) /* a white value? */ |
| 458 | hasclears = 1; /* table will have to be cleared */ |
| 459 | } |
| 460 | } |
| 461 | if (g->gcstate == GCSatomic && hasclears) |
| 462 | linkgclist(h, g->weak); /* has to be cleared later */ |
| 463 | else |
| 464 | linkgclist(h, g->grayagain); /* must retraverse it in atomic phase */ |
| 465 | } |
| 466 | |
| 467 | |
| 468 | /* |
no test coverage detected