** Traverse an ephemeron table and link it to proper list. Returns true ** iff any object was marked during this traversal (which implies that ** convergence has to continue). During propagation phase, keep table ** in 'grayagain' list, to be visited again in the atomic phase. In ** the atomic phase, if table has any white->white entry, it has to ** be revisited during ephemeron convergence (as th
| 392 | ** (in the atomic phase). |
| 393 | */ |
| 394 | static int traverseephemeron (global_State *g, Table *h) { |
| 395 | int marked = 0; /* true if an object is marked in this traversal */ |
| 396 | int hasclears = 0; /* true if table has white keys */ |
| 397 | int hasww = 0; /* true if table has entry "white-key -> white-value" */ |
| 398 | Node *n, *limit = gnodelast(h); |
| 399 | unsigned int i; |
| 400 | /* traverse array part */ |
| 401 | for (i = 0; i < h->sizearray; i++) { |
| 402 | if (valiswhite(&h->array[i])) { |
| 403 | marked = 1; |
| 404 | reallymarkobject(g, gcvalue(&h->array[i])); |
| 405 | } |
| 406 | } |
| 407 | /* traverse hash part */ |
| 408 | for (n = gnode(h, 0); n < limit; n++) { |
| 409 | checkdeadkey(n); |
| 410 | if (ttisnil(gval(n))) /* entry is empty? */ |
| 411 | removeentry(n); /* remove it */ |
| 412 | else if (iscleared(g, gkey(n))) { /* key is not marked (yet)? */ |
| 413 | hasclears = 1; /* table must be cleared */ |
| 414 | if (valiswhite(gval(n))) /* value not marked yet? */ |
| 415 | hasww = 1; /* white-white entry */ |
| 416 | } |
| 417 | else if (valiswhite(gval(n))) { /* value not marked yet? */ |
| 418 | marked = 1; |
| 419 | reallymarkobject(g, gcvalue(gval(n))); /* mark it now */ |
| 420 | } |
| 421 | } |
| 422 | /* link table into proper list */ |
| 423 | if (g->gcstate == GCSpropagate) |
| 424 | linkgclist(h, g->grayagain); /* must retraverse it in atomic phase */ |
| 425 | else if (hasww) /* table has white->white entries? */ |
| 426 | linkgclist(h, g->ephemeron); /* have to propagate again */ |
| 427 | else if (hasclears) /* table has white keys? */ |
| 428 | linkgclist(h, g->allweak); /* may have to clean white keys */ |
| 429 | return marked; |
| 430 | } |
| 431 | |
| 432 | |
| 433 | static void traversestrongtable (global_State *g, Table *h) { |
no test coverage detected