From e92a6012559b6462d11cc154e2debf57dac672d8 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Mon, 22 Sep 2008 22:08:56 -0700 Subject: [PATCH] Visitor dispatch optimization --- Cython/Compiler/Visitor.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/Visitor.py b/Cython/Compiler/Visitor.py index 2b855086..6c711ffd 100644 --- a/Cython/Compiler/Visitor.py +++ b/Cython/Compiler/Visitor.py @@ -16,12 +16,11 @@ class BasicVisitor(object): self.dispatch_table = {} def visit(self, obj): - pattern = "visit_%s" cls = obj.__class__ - mname = pattern % cls.__name__ - m = self.dispatch_table.get(mname) + m = self.dispatch_table.get(cls.__name__) if m is None: # Must resolve, try entire hierarchy + pattern = "visit_%s" mro = inspect.getmro(cls) for cls in mro: m = getattr(self, pattern % cls.__name__, None) @@ -33,7 +32,7 @@ class BasicVisitor(object): print self.access_path[-1][0].pos print self.access_path[-1][0].__dict__ raise RuntimeError("Visitor does not accept object: %s" % obj) - self.dispatch_table[mname] = m + self.dispatch_table[cls.__name__] = m return m(obj) class TreeVisitor(BasicVisitor): -- 2.26.2