Skip to content

Commit d89ecdc

Browse files
committed
Count visited in update_refs
1 parent bb3fc94 commit d89ecdc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Python/gc.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,12 @@ validate_consistent_old_space(PyGC_Head *head)
483483
/* Set all gc_refs = ob_refcnt. After this, gc_refs is > 0 and
484484
* PREV_MASK_COLLECTING bit is set for all objects in containers.
485485
*/
486-
static void
486+
static Py_ssize_t
487487
update_refs(PyGC_Head *containers)
488488
{
489489
PyGC_Head *next;
490490
PyGC_Head *gc = GC_NEXT(containers);
491+
Py_ssize_t visited = 0;
491492

492493
while (gc != containers) {
493494
next = GC_NEXT(gc);
@@ -519,7 +520,9 @@ update_refs(PyGC_Head *containers)
519520
*/
520521
_PyObject_ASSERT(op, gc_get_refs(gc) != 0);
521522
gc = next;
523+
visited++;
522524
}
525+
return visited;
523526
}
524527

525528
/* A traversal callback for subtract_refs. */
@@ -663,13 +666,12 @@ visit_reachable(PyObject *op, void *arg)
663666
* But _gc_next in unreachable list has NEXT_MASK_UNREACHABLE flag.
664667
* So we can not gc_list_* functions for unreachable until we remove the flag.
665668
*/
666-
static Py_ssize_t
669+
static void
667670
move_unreachable(PyGC_Head *young, PyGC_Head *unreachable)
668671
{
669672
// previous elem in the young list, used for restore gc_prev.
670673
PyGC_Head *prev = young;
671674
PyGC_Head *gc = GC_NEXT(young);
672-
Py_ssize_t visited = 0;
673675

674676
/* Invariants: all objects "to the left" of us in young are reachable
675677
* (directly or indirectly) from outside the young list as it was at entry.
@@ -684,7 +686,6 @@ move_unreachable(PyGC_Head *young, PyGC_Head *unreachable)
684686
/* Record which old space we are in, and set NEXT_MASK_UNREACHABLE bit for convenience */
685687
uintptr_t flags = NEXT_MASK_UNREACHABLE | (gc->_gc_next & _PyGC_NEXT_MASK_OLD_SPACE_1);
686688
while (gc != young) {
687-
visited++;
688689
if (gc_get_refs(gc)) {
689690
/* gc is definitely reachable from outside the
690691
* original 'young'. Mark it as such, and traverse
@@ -741,7 +742,6 @@ move_unreachable(PyGC_Head *young, PyGC_Head *unreachable)
741742
young->_gc_next &= _PyGC_PREV_MASK;
742743
// don't let the pollution of the list head's next pointer leak
743744
unreachable->_gc_next &= _PyGC_PREV_MASK;
744-
return visited;
745745
}
746746

747747
/* In theory, all tuples should be younger than the
@@ -1251,7 +1251,7 @@ deduce_unreachable(PyGC_Head *base, PyGC_Head *unreachable) {
12511251
* refcount greater than 0 when all the references within the
12521252
* set are taken into account).
12531253
*/
1254-
update_refs(base); // gc_prev is used for gc_refs
1254+
Py_ssize_t visited = update_refs(base); // gc_prev is used for gc_refs
12551255
subtract_refs(base);
12561256

12571257
/* Leave everything reachable from outside base in base, and move
@@ -1289,7 +1289,7 @@ deduce_unreachable(PyGC_Head *base, PyGC_Head *unreachable) {
12891289
* the reachable objects instead. But this is a one-time cost, probably not
12901290
* worth complicating the code to speed just a little.
12911291
*/
1292-
Py_ssize_t visited = move_unreachable(base, unreachable); // gc_prev is pointer again
1292+
move_unreachable(base, unreachable); // gc_prev is pointer again
12931293
validate_list(base, collecting_clear_unreachable_clear);
12941294
validate_list(unreachable, collecting_set_unreachable_set);
12951295
return visited;

0 commit comments

Comments
 (0)