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
Gwenaël Samain
cython
Commits
dd08655b
Commit
dd08655b
authored
Dec 27, 2014
by
scoder
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #345 from larsmans/pysequence
Use PySequence_List, PySequence_Tuple
parents
240f990f
9793b17b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
12 deletions
+55
-12
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+29
-10
tests/run/list.pyx
tests/run/list.pyx
+12
-0
tests/run/tuple.pyx
tests/run/tuple.pyx
+14
-2
No files found.
Cython/Compiler/Optimize.py
View file @
dd08655b
...
...
@@ -2037,29 +2037,48 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
)
return
node
PySequence_List_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
list_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"it"
,
PyrexTypes
.
py_object_type
,
None
)])
def
_handle_simple_function_list
(
self
,
node
,
function
,
pos_args
):
"""Turn list(ob) into PySequence_List(ob).
"""
if
len
(
pos_args
)
!=
1
:
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
)
PyList_AsTuple_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
tuple_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"list"
,
Builtin
.
list_type
,
None
)
])
PySequence_Tuple_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
tuple_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"it"
,
PyrexTypes
.
py_object_type
,
None
)])
def
_handle_simple_function_tuple
(
self
,
node
,
function
,
pos_args
):
"""Replace tuple([...]) by
a call to PyList_As
Tuple.
"""Replace tuple([...]) by
PyList_AsTuple or PySequence_
Tuple.
"""
if
len
(
pos_args
)
!=
1
:
return
node
arg
=
pos_args
[
0
]
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
pos_args
[
0
]
=
arg
.
as_none_safe_node
(
"'NoneType' object is not iterable"
)
if
arg
.
type
is
Builtin
.
list_type
:
pos_args
[
0
]
=
arg
.
as_none_safe_node
(
"'NoneType' object is not iterable"
)
return
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"PyList_AsTuple"
,
self
.
PyList_AsTuple_func_type
,
args
=
pos_args
,
is_temp
=
node
.
is_temp
)
return
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"PyList_AsTuple"
,
self
.
PyList_AsTuple_func_type
,
args
=
pos_args
,
is_temp
=
node
.
is_temp
)
else
:
return
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"PySequence_Tuple"
,
self
.
PySequence_Tuple_func_type
,
args
=
pos_args
,
is_temp
=
node
.
is_temp
)
PySet_New_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
set_type
,
[
...
...
tests/run/list.pyx
View file @
dd08655b
...
...
@@ -41,6 +41,18 @@ def k(obj1, obj2, obj3, obj4, obj5):
obj1
=
[
17
,
42
,
88
]
return
obj1
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
test_list_call
(
ob
):
"""
>>> def f():
... yield 1
... yield 2
...
>>> list(f())
[1, 2]
"""
return
list
(
ob
)
def
test_list_sort
():
"""
>>> test_list_sort()
...
...
tests/run/tuple.pyx
View file @
dd08655b
...
...
@@ -114,9 +114,21 @@ def tuple_of_args_tuple(*args):
return
tuple
(
tuple
(
tuple
(
args
)))
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode//SimpleCallNode'
)
def
tuple_of_object
(
ob
):
"""
>>> tuple(type(1))
Traceback (most recent call last):
TypeError: 'type' object is not iterable
>>> sorted(tuple(set([1, 2, 3])))
[1, 2, 3]
"""
return
tuple
(
ob
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode
//SimpleCallNode
'
,
'//PythonCapiCallNode'
'//SimpleCallNode'
,
'//PythonCapiCallNode
//PythonCapiCallNode
'
)
def
tuple_of_tuple_or_none
(
tuple
x
):
"""
...
...
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