diff Objects/funcobject.c @ 37756:7b2e436a4a21 legacy-trunk

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
author Thomas Wouters <thomas@python.org>
date Sat, 15 Apr 2006 21:47:09 +0000
parents d1547426ab61
children 934ba5be8f3f
line wrap: on
line diff
--- a/Objects/funcobject.c	Sat Apr 15 21:41:56 2006 +0000
+++ b/Objects/funcobject.c	Sat Apr 15 21:47:09 2006 +0000
@@ -466,47 +466,14 @@
 static int
 func_traverse(PyFunctionObject *f, visitproc visit, void *arg)
 {
-	int err;
-	if (f->func_code) {
-		err = visit(f->func_code, arg);
-		if (err)
-			return err;
-	}
-	if (f->func_globals) {
-		err = visit(f->func_globals, arg);
-		if (err)
-			return err;
-	}
-	if (f->func_module) {
-		err = visit(f->func_module, arg);
-		if (err)
-			return err;
-	}
-	if (f->func_defaults) {
-		err = visit(f->func_defaults, arg);
-		if (err)
-			return err;
-	}
-	if (f->func_doc) {
-		err = visit(f->func_doc, arg);
-		if (err)
-			return err;
-	}
-	if (f->func_name) {
-		err = visit(f->func_name, arg);
-		if (err)
-			return err;
-	}
-	if (f->func_dict) {
-		err = visit(f->func_dict, arg);
-		if (err)
-			return err;
-	}
-	if (f->func_closure) {
-		err = visit(f->func_closure, arg);
-		if (err)
-			return err;
-	}
+	Py_VISIT(f->func_code);
+	Py_VISIT(f->func_globals);
+	Py_VISIT(f->func_module);
+	Py_VISIT(f->func_defaults);
+	Py_VISIT(f->func_doc);
+	Py_VISIT(f->func_name);
+	Py_VISIT(f->func_dict);
+	Py_VISIT(f->func_closure);
 	return 0;
 }
 
@@ -647,9 +614,8 @@
 static int
 cm_traverse(classmethod *cm, visitproc visit, void *arg)
 {
-	if (!cm->cm_callable)
-		return 0;
-	return visit(cm->cm_callable, arg);
+	Py_VISIT(cm->cm_callable);
+	return 0;
 }
 
 static int
@@ -806,9 +772,8 @@
 static int
 sm_traverse(staticmethod *sm, visitproc visit, void *arg)
 {
-	if (!sm->sm_callable)
-		return 0;
-	return visit(sm->sm_callable, arg);
+	Py_VISIT(sm->sm_callable);
+	return 0;
 }
 
 static int