Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
using a custom, nearly-identical macro. This probably changes how some of
these functions are compiled, which may result in fractionally slower (or
faster) execution. Considering the nature of traversal, visiting much of the
address space in unpredictable patterns, I'd argue the code readability and
maintainability is well worth it ;P
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 1debd23..78961f3 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2276,14 +2276,8 @@
Py_ssize_t i;
PyObject *x;
- for (i = o->ob_size; --i >= 0; ) {
- x = o->ob_item[i];
- if (x != NULL) {
- int err = visit(x, arg);
- if (err)
- return err;
- }
- }
+ for (i = o->ob_size; --i >= 0; )
+ Py_VISIT(o->ob_item[i]);
return 0;
}
@@ -2779,9 +2773,8 @@
static int
listiter_traverse(listiterobject *it, visitproc visit, void *arg)
{
- if (it->it_seq == NULL)
- return 0;
- return visit((PyObject *)it->it_seq, arg);
+ Py_VISIT(it->it_seq);
+ return 0;
}
static PyObject *
@@ -2898,9 +2891,8 @@
static int
listreviter_traverse(listreviterobject *it, visitproc visit, void *arg)
{
- if (it->it_seq == NULL)
- return 0;
- return visit((PyObject *)it->it_seq, arg);
+ Py_VISIT(it->it_seq);
+ return 0;
}
static PyObject *