** 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.) */
| 822 | ** list is finished. ('*countout' gets the number of elements traversed.) |
| 823 | */ |
| 824 | static GCObject **sweeplist (lua_State *L, GCObject **p, int countin, |
| 825 | int *countout) { |
| 826 | global_State *g = G(L); |
| 827 | int ow = otherwhite(g); |
| 828 | int i; |
| 829 | int white = luaC_white(g); /* current white */ |
| 830 | for (i = 0; *p != NULL && i < countin; i++) { |
| 831 | GCObject *curr = *p; |
| 832 | int marked = curr->marked; |
| 833 | if (isdeadm(ow, marked)) { /* is 'curr' dead? */ |
| 834 | *p = curr->next; /* remove 'curr' from list */ |
| 835 | freeobj(L, curr); /* erase 'curr' */ |
| 836 | } |
| 837 | else { /* change mark to 'white' */ |
| 838 | curr->marked = cast_byte((marked & ~maskgcbits) | white); |
| 839 | p = &curr->next; /* go to next element */ |
| 840 | } |
| 841 | } |
| 842 | if (countout) |
| 843 | *countout = i; /* number of elements traversed */ |
| 844 | return (*p == NULL) ? NULL : p; |
| 845 | } |
| 846 | |
| 847 | |
| 848 | /* |
no test coverage detected