MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / traverseephemeron

Function traverseephemeron

lib/lua/src/lgc.c:480–520  ·  view source on GitHub ↗

** 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

Source from the content-addressed store, hash-verified

478** by 'genlink'.
479*/
480static int traverseephemeron (global_State *g, Table *h, int inv) {
481 int marked = 0; /* true if an object is marked in this traversal */
482 int hasclears = 0; /* true if table has white keys */
483 int hasww = 0; /* true if table has entry "white-key -> white-value" */
484 unsigned int i;
485 unsigned int asize = luaH_realasize(h);
486 unsigned int nsize = sizenode(h);
487 /* traverse array part */
488 for (i = 0; i < asize; i++) {
489 if (valiswhite(&h->array[i])) {
490 marked = 1;
491 reallymarkobject(g, gcvalue(&h->array[i]));
492 }
493 }
494 /* traverse hash part; if 'inv', traverse descending
495 (see 'convergeephemerons') */
496 for (i = 0; i < nsize; i++) {
497 Node *n = inv ? gnode(h, nsize - 1 - i) : gnode(h, i);
498 if (isempty(gval(n))) /* entry is empty? */
499 clearkey(n); /* clear its key */
500 else if (iscleared(g, gckeyN(n))) { /* key is not marked (yet)? */
501 hasclears = 1; /* table must be cleared */
502 if (valiswhite(gval(n))) /* value not marked yet? */
503 hasww = 1; /* white-white entry */
504 }
505 else if (valiswhite(gval(n))) { /* value not marked yet? */
506 marked = 1;
507 reallymarkobject(g, gcvalue(gval(n))); /* mark it now */
508 }
509 }
510 /* link table into proper list */
511 if (g->gcstate == GCSpropagate)
512 linkgclist(h, g->grayagain); /* must retraverse it in atomic phase */
513 else if (hasww) /* table has white->white entries? */
514 linkgclist(h, g->ephemeron); /* have to propagate again */
515 else if (hasclears) /* table has white keys? */
516 linkgclist(h, g->allweak); /* may have to clean white keys */
517 else
518 genlink(g, obj2gco(h)); /* check whether collector still needs to see it */
519 return marked;
520}
521
522
523static void traversestrongtable (global_State *g, Table *h) {

Callers 2

traversetableFunction · 0.85
convergeephemeronsFunction · 0.85

Calls 5

luaH_realasizeFunction · 0.85
reallymarkobjectFunction · 0.85
clearkeyFunction · 0.85
isclearedFunction · 0.85
genlinkFunction · 0.85

Tested by

no test coverage detected