** sweep at most 'countin' elements from a list of GCObjects erasing dead ** objects, where a dead object is one marked with the old (non current) ** white; change all non-dead objects back to white, preparing for next ** collection cycle. Return where to continue the traversal or NULL if ** list is finished. ('*countout' gets the number of elements traversed.) */
| 753 | ** list is finished. ('*countout' gets the number of elements traversed.) |
| 754 | */ |
| 755 | static GCObject **sweeplist (lua_State *L, GCObject **p, int countin, |
| 756 | int *countout) { |
| 757 | global_State *g = G(L); |
| 758 | int ow = otherwhite(g); |
| 759 | int i; |
| 760 | int white = luaC_white(g); /* current white */ |
| 761 | for (i = 0; *p != NULL && i < countin; i++) { |
| 762 | GCObject *curr = *p; |
| 763 | int marked = curr->marked; |
| 764 | if (isdeadm(ow, marked)) { /* is 'curr' dead? */ |
| 765 | *p = curr->next; /* remove 'curr' from list */ |
| 766 | freeobj(L, curr); /* erase 'curr' */ |
| 767 | } |
| 768 | else { /* change mark to 'white' */ |
| 769 | curr->marked = cast_byte((marked & maskcolors) | white); |
| 770 | p = &curr->next; /* go to next element */ |
| 771 | } |
| 772 | } |
| 773 | if (countout) |
| 774 | *countout = i; /* number of elements traversed */ |
| 775 | return (*p == NULL) ? NULL : p; |
| 776 | } |
| 777 | |
| 778 | |
| 779 | /* |
no test coverage detected