Commit b8d4929e authored by Stefan Behnel's avatar Stefan Behnel

avoid some unnecessary round trips when creating immutable objects

parent edb8f353
...@@ -1972,13 +1972,13 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform): ...@@ -1972,13 +1972,13 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
""" """
if len(pos_args) != 1: if len(pos_args) != 1:
return node return node
list_arg = pos_args[0] arg = pos_args[0]
if list_arg.type is not Builtin.list_type: if arg.type is Builtin.tuple_type and not arg.may_be_none():
return arg
if arg.type is not Builtin.list_type:
return node return node
if not isinstance(list_arg, (ExprNodes.ComprehensionNode, pos_args[0] = arg.as_none_safe_node(
ExprNodes.ListNode)): "'NoneType' object is not iterable")
pos_args[0] = list_arg.as_none_safe_node(
"'NoneType' object is not iterable")
return ExprNodes.PythonCapiCallNode( return ExprNodes.PythonCapiCallNode(
node.pos, "PyList_AsTuple", self.PyList_AsTuple_func_type, node.pos, "PyList_AsTuple", self.PyList_AsTuple_func_type,
...@@ -2031,6 +2031,8 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform): ...@@ -2031,6 +2031,8 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
pos_args = [ExprNodes.NullNode(node.pos)] pos_args = [ExprNodes.NullNode(node.pos)]
elif len(pos_args) > 1: elif len(pos_args) > 1:
return node return node
elif pos_args[0].type is Builtin.frozenset_type and not pos_args[0].may_be_none():
return pos_args[0]
# PyFrozenSet_New(it) is better than a generic Python call to frozenset(it) # PyFrozenSet_New(it) is better than a generic Python call to frozenset(it)
return ExprNodes.PythonCapiCallNode( return ExprNodes.PythonCapiCallNode(
node.pos, "__Pyx_PyFrozenSet_New", node.pos, "__Pyx_PyFrozenSet_New",
......
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