From 7837b470b453268d967ac4defbd092783e32c950 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 11 Nov 2010 21:08:34 +0100 Subject: [PATCH] another bit less overhead inside of Visitor classes --- Cython/Compiler/Visitor.pxd | 5 +++-- Cython/Compiler/Visitor.py | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cython/Compiler/Visitor.pxd b/Cython/Compiler/Visitor.pxd index 46ab02fb..4ca2e3f7 100644 --- a/Cython/Compiler/Visitor.pxd +++ b/Cython/Compiler/Visitor.pxd @@ -3,14 +3,15 @@ cimport cython cdef class BasicVisitor: cdef dict dispatch_table cpdef visit(self, obj) - cpdef find_handler(self, obj) + cdef _visit(self, obj) + cdef find_handler(self, obj) cdef class TreeVisitor(BasicVisitor): cdef public list access_path cpdef visitchild(self, child, parent, attrname, idx) @cython.locals(idx=int) cdef dict _visitchildren(self, parent, attrs) -# cpdef visitchildren(self, parent, attrs=*) + cpdef visitchildren(self, parent, attrs=*) cdef class VisitorTransform(TreeVisitor): cpdef visitchildren(self, parent, attrs=*) diff --git a/Cython/Compiler/Visitor.py b/Cython/Compiler/Visitor.py index 224dbc42..6b89cca9 100644 --- a/Cython/Compiler/Visitor.py +++ b/Cython/Compiler/Visitor.py @@ -20,6 +20,9 @@ class BasicVisitor(object): self.dispatch_table = {} def visit(self, obj): + return self._visit(obj) + + def _visit(self, obj): try: handler_method = self.dispatch_table[type(obj)] except KeyError: @@ -176,7 +179,7 @@ class TreeVisitor(BasicVisitor): def visitchild(self, child, parent, attrname, idx): self.access_path.append((parent, attrname, idx)) try: - result = self.visit(child) + result = self._visit(child) except Errors.CompileError: raise except Exception, e: @@ -256,7 +259,7 @@ class VisitorTransform(TreeVisitor): return node def __call__(self, root): - return self.visit(root) + return self._visit(root) class CythonTransform(VisitorTransform): """ @@ -388,7 +391,7 @@ class PrintTree(TreeVisitor): def __call__(self, tree, phase=None): print("Parse tree dump at phase '%s'" % phase) - self.visit(tree) + self._visit(tree) return tree # Don't do anything about process_list, the defaults gives -- 2.26.2