Commit 83781ad5 authored by Stefan Behnel's avatar Stefan Behnel

fix final optimisations for calls inside of assignments

parent 3f83a9b3
...@@ -350,6 +350,10 @@ class FinalOptimizePhase(Visitor.CythonTransform): ...@@ -350,6 +350,10 @@ class FinalOptimizePhase(Visitor.CythonTransform):
- isinstance -> typecheck for cdef types - isinstance -> typecheck for cdef types
""" """
def visit_SingleAssignmentNode(self, node): def visit_SingleAssignmentNode(self, node):
"""Avoid redundant initialisation of local variables before their
first assignment.
"""
self.visitchildren(node)
if node.first: if node.first:
lhs = node.lhs lhs = node.lhs
lhs.lhs_of_first_assignment = True lhs.lhs_of_first_assignment = True
...@@ -360,6 +364,9 @@ class FinalOptimizePhase(Visitor.CythonTransform): ...@@ -360,6 +364,9 @@ class FinalOptimizePhase(Visitor.CythonTransform):
return node return node
def visit_SimpleCallNode(self, node): def visit_SimpleCallNode(self, node):
"""Replace generic calls to isinstance(x, type) by a more efficient
type check.
"""
self.visitchildren(node) self.visitchildren(node)
if node.function.type.is_cfunction and isinstance(node.function, ExprNodes.NameNode): if node.function.type.is_cfunction and isinstance(node.function, ExprNodes.NameNode):
if node.function.name == 'isinstance': if node.function.name == 'isinstance':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment