summaryrefslogtreecommitdiff
path: root/Cython/Compiler/Optimize.py
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2020-04-08 10:30:02 +0200
committerStefan Behnel <stefan_ml@behnel.de>2020-04-08 10:30:02 +0200
commit4ef1a091ba19e330eb02e6081839abad3769cd41 (patch)
treedcfe4b8aa828e3707cfd261ffcf7d7c445f1328d /Cython/Compiler/Optimize.py
parentc43bd7771fe6fe0064cdfa276f49fd693c277226 (diff)
downloadcython-optimise_pysequence_list.tar.gz
Avoid calling PySequence_List() in some cases where we can see that the argument is a new list already.optimise_pysequence_list
Diffstat (limited to 'Cython/Compiler/Optimize.py')
-rw-r--r--Cython/Compiler/Optimize.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py
index 01f823b6f..d836409f6 100644
--- a/Cython/Compiler/Optimize.py
+++ b/Cython/Compiler/Optimize.py
@@ -1753,7 +1753,11 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
# Interestingly, PySequence_List works on a lot of non-sequence
# things as well.
list_node = loop_node = ExprNodes.PythonCapiCallNode(
- node.pos, "PySequence_List", self.PySequence_List_func_type,
+ node.pos,
+ "__Pyx_PySequence_ListKeepNew"
+ if arg.is_temp and arg.type in (PyrexTypes.py_object_type, Builtin.list_type)
+ else "PySequence_List",
+ self.PySequence_List_func_type,
args=pos_args, is_temp=True)
result_node = UtilNodes.ResultRefNode(
@@ -2415,8 +2419,14 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
return node
arg = pos_args[0]
return ExprNodes.PythonCapiCallNode(
- node.pos, "PySequence_List", self.PySequence_List_func_type,
- args=pos_args, is_temp=node.is_temp)
+ node.pos,
+ "__Pyx_PySequence_ListKeepNew"
+ if node.is_temp and arg.is_temp and arg.type in (PyrexTypes.py_object_type, Builtin.list_type)
+ else "PySequence_List",
+ self.PySequence_List_func_type,
+ args=pos_args,
+ is_temp=node.is_temp,
+ )
PyList_AsTuple_func_type = PyrexTypes.CFuncType(
Builtin.tuple_type, [