| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| if not entering(node): | ||
| return | ||
| for propname, propvalue in vars(node).items(): | ||
| self.visit(propvalue) |
There was a problem hiding this comment.
I'd like to suggest a slightly more verbose way of writing this method. It's a nit, so feel free to ignore. As you know, I've been trying to promote the idea of self-documenting code in my reviews :) Here, the value I think this brings is that it gives an explicit meaning to the return value of the process_node method.
def visit_node(self, node):
nodename = type(node).__name__
process_node = getattr(self, 'visit_{}'.format(nodename), self.generic_visit)
should_continue = process_node(node)
if should_continue:
for propname, propvalue in vars(node).items():
self.visit(propvalue)
Sorry, something went wrong.
This includes some performance tests to compare the visitor and a traversal. Locally, the visitor is twice as fast. This is the most basic Visitor pattern. I've had versions that were more generic, and performance gains vanished quickly. In particular optionally collecting results on exit halfed the performance benefits. If we want to factor that in, we should have an independent base class for that.
| Back | FazBrowse Home | New Git URL |
This includes some performance tests to compare the visitor and a
traversal. Locally, the visitor is twice as fast.
This is the most basic Visitor pattern. I've had versions that were
more generic, and performance gains vanished quickly. In particular
optionally collecting results on exit halfed the performance benefits.
If we want to factor that in, we should have an independent base class
for that.
This should fix #68, I think.