MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / traverseephemeron

Function traverseephemeron

3rd/lua-5.4.3/src/lgc.c:474–514  ·  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

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