summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2006-04-15 21:47:09 (GMT)
committerThomas Wouters <thomas@python.org>2006-04-15 21:47:09 (GMT)
commitc6e55068cad6f2178981eec4f0a0a583b8bba21a (patch)
tree19a89bbe082dadc70c1413030e5a5b8dacac757c /Modules
parent447d095976fd532bf1882bf7afeb52473ff8673c (diff)
downloadcpython-c6e55068cad6f2178981eec4f0a0a583b8bba21a.zip
cpython-c6e55068cad6f2178981eec4f0a0a583b8bba21a.tar.gz
cpython-c6e55068cad6f2178981eec4f0a0a583b8bba21a.tar.bz2
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
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_csv.c35
-rw-r--r--Modules/arraymodule.c3
-rw-r--r--Modules/cPickle.c51
-rw-r--r--Modules/operator.c6
-rw-r--r--Modules/pyexpat.c9
-rw-r--r--Modules/zipimport.c8
6 files changed, 38 insertions, 74 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 500d36e..67d5d9f 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -48,7 +48,16 @@ module instead.
} \
} while (0)
#endif
-
+#ifndef Py_VISIT
+#define Py_VISIT(op) \
+ do { \
+ if (op) { \
+ int vret = visit((PyObject *)(op), arg); \
+ if (vret) \
+ return vret; \
+ } \
+ } while (0)
+#endif
/* end 2.2 compatibility macros */
@@ -825,16 +834,9 @@ Reader_dealloc(ReaderObj *self)
static int
Reader_traverse(ReaderObj *self, visitproc visit, void *arg)
{
- int err;
-#define VISIT(SLOT) \
- if (SLOT) { \
- err = visit((PyObject *)(SLOT), arg); \
- if (err) \
- return err; \
- }
- VISIT(self->dialect);
- VISIT(self->input_iter);
- VISIT(self->fields);
+ Py_VISIT(self->dialect);
+ Py_VISIT(self->input_iter);
+ Py_VISIT(self->fields);
return 0;
}
@@ -1255,15 +1257,8 @@ Writer_dealloc(WriterObj *self)
static int
Writer_traverse(WriterObj *self, visitproc visit, void *arg)
{
- int err;
-#define VISIT(SLOT) \
- if (SLOT) { \
- err = visit((PyObject *)(SLOT), arg); \
- if (err) \
- return err; \
- }
- VISIT(self->dialect);
- VISIT(self->writeline);
+ Py_VISIT(self->dialect);
+ Py_VISIT(self->writeline);
return 0;
}
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 4324f39..4551342 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -2061,8 +2061,7 @@ arrayiter_dealloc(arrayiterobject *it)
static int
arrayiter_traverse(arrayiterobject *it, visitproc visit, void *arg)
{
- if (it->ao != NULL)
- return visit((PyObject *)(it->ao), arg);
+ Py_VISIT(it->ao);
return 0;
}
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 1d99fcb..18df599 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -2909,22 +2909,14 @@ Pickler_dealloc(Picklerobject *self)
static int
Pickler_traverse(Picklerobject *self, visitproc visit, void *arg)
{
- int err;
-#define VISIT(SLOT) \
- if (SLOT) { \
- err = visit((PyObject *)(SLOT), arg); \
- if (err) \
- return err; \
- }
- VISIT(self->write);
- VISIT(self->memo);
- VISIT(self->fast_memo);
- VISIT(self->arg);
- VISIT(self->file);
- VISIT(self->pers_func);
- VISIT(self->inst_pers_func);
- VISIT(self->dispatch_table);
-#undef VISIT
+ Py_VISIT(self->write);
+ Py_VISIT(self->memo);
+ Py_VISIT(self->fast_memo);
+ Py_VISIT(self->arg);
+ Py_VISIT(self->file);
+ Py_VISIT(self->pers_func);
+ Py_VISIT(self->inst_pers_func);
+ Py_VISIT(self->dispatch_table);
return 0;
}
@@ -5258,24 +5250,15 @@ Unpickler_dealloc(Unpicklerobject *self)
static int
Unpickler_traverse(Unpicklerobject *self, visitproc visit, void *arg)
{
- int err;
-
-#define VISIT(SLOT) \
- if (SLOT) { \
- err = visit((PyObject *)(SLOT), arg); \
- if (err) \
- return err; \
- }
- VISIT(self->readline);
- VISIT(self->read);
- VISIT(self->file);
- VISIT(self->memo);
- VISIT(self->stack);
- VISIT(self->pers_func);
- VISIT(self->arg);
- VISIT(self->last_string);
- VISIT(self->find_class);
-#undef VISIT
+ Py_VISIT(self->readline);
+ Py_VISIT(self->read);
+ Py_VISIT(self->file);
+ Py_VISIT(self->memo);
+ Py_VISIT(self->stack);
+ Py_VISIT(self->pers_func);
+ Py_VISIT(self->arg);
+ Py_VISIT(self->last_string);
+ Py_VISIT(self->find_class);
return 0;
}
diff --git a/Modules/operator.c b/Modules/operator.c
index 53144f1..25b3999 100644
--- a/Modules/operator.c
+++ b/Modules/operator.c
@@ -358,8 +358,7 @@ itemgetter_dealloc(itemgetterobject *ig)
static int
itemgetter_traverse(itemgetterobject *ig, visitproc visit, void *arg)
{
- if (ig->item)
- return visit(ig->item, arg);
+ Py_VISIT(ig->item);
return 0;
}
@@ -497,8 +496,7 @@ attrgetter_dealloc(attrgetterobject *ag)
static int
attrgetter_traverse(attrgetterobject *ag, visitproc visit, void *arg)
{
- if (ag->attr)
- return visit(ag->attr, arg);
+ Py_VISIT(ag->attr);
return 0;
}
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index fbef4e1..16f0137 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1655,13 +1655,8 @@ static int
xmlparse_traverse(xmlparseobject *op, visitproc visit, void *arg)
{
int i, err;
- for (i = 0; handler_info[i].name != NULL; i++) {
- if (!op->handlers[i])
- continue;
- err = visit(op->handlers[i], arg);
- if (err)
- return err;
- }
+ for (i = 0; handler_info[i].name != NULL; i++)
+ Py_VISIT(op->handlers[i]);
return 0;
}
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 3e37656..d59ebd8 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -170,13 +170,7 @@ static int
zipimporter_traverse(PyObject *obj, visitproc visit, void *arg)
{
ZipImporter *self = (ZipImporter *)obj;
- int err;
-
- if (self->files != NULL) {
- err = visit(self->files, arg);
- if (err)
- return err;
- }
+ Py_VISIT(self->files);
return 0;
}