Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
34714637
Commit
34714637
authored
Apr 08, 2020
by
Stefan Behnel
Committed by
GitHub
Apr 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid calling PySequence_List() in some cases if the argument is a new list already. (GH-3494)
parent
98319229
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
5 deletions
+27
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+7
-2
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+13
-3
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+7
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
34714637
...
...
@@ -7797,8 +7797,11 @@ class SequenceNode(ExprNode):
starred_target
.
allocate
(
code
)
target_list
=
starred_target
.
result
()
code
.
putln
(
"%s =
PySequence_List
(%s); %s"
%
(
code
.
putln
(
"%s =
%s
(%s); %s"
%
(
target_list
,
"__Pyx_PySequence_ListKeepNew"
if
(
not
iterator_temp
and
rhs
.
is_temp
and
rhs
.
type
in
(
py_object_type
,
list_type
))
else
"PySequence_List"
,
iterator_temp
or
rhs
.
py_result
(),
code
.
error_goto_if_null
(
target_list
,
self
.
pos
)))
starred_target
.
generate_gotref
(
code
)
...
...
@@ -8531,7 +8534,9 @@ class MergedSequenceNode(ExprNode):
else
:
code
.
putln
(
"%s = %s(%s); %s"
%
(
self
.
result
(),
'PySet_New'
if
is_set
else
'PySequence_List'
,
'PySet_New'
if
is_set
else
"__Pyx_PySequence_ListKeepNew"
if
item
.
is_temp
and
item
.
type
in
(
py_object_type
,
list_type
)
else
"PySequence_List"
,
item
.
py_result
(),
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
self
.
generate_gotref
(
code
)
...
...
Cython/Compiler/Optimize.py
View file @
34714637
...
...
@@ -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
,
[
...
...
Cython/Utility/ModuleSetupCode.c
View file @
34714637
...
...
@@ -760,6 +760,13 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
#define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PySequence_ListKeepNew(obj) \
(likely(PyList_CheckExact(obj) && Py_REFCNT(obj) == 1) ? __Pyx_NewRef(obj) : PySequence_List(obj))
#else
#define __Pyx_PySequence_ListKeepNew(obj) PySequence_List(obj)
#endif
#ifndef PySet_CheckExact
#define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment