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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
680bd22d
Commit
680bd22d
authored
May 04, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enable .pop() optimisation also for typed lists
parent
485c6f90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+2
-0
tests/run/list_pop.pyx
tests/run/list_pop.pyx
+58
-0
No files found.
Cython/Compiler/Optimize.py
View file @
680bd22d
...
...
@@ -1693,6 +1693,8 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
return
node
_handle_simple_method_list_pop
=
_handle_simple_method_object_pop
PyList_Append_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_int_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"list"
,
PyrexTypes
.
py_object_type
,
None
),
...
...
tests/run/list_pop.pyx
View file @
680bd22d
...
...
@@ -32,6 +32,30 @@ def simple_pop(L):
"""
return
L
.
pop
()
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode/AttributeNode'
)
def
simple_pop_typed
(
list
L
):
"""
>>> L = list(range(10))
>>> simple_pop_typed(L)
9
>>> simple_pop_typed(L)
8
>>> L
[0, 1, 2, 3, 4, 5, 6, 7]
>>> while L:
... _ = simple_pop_typed(L)
>>> L
[]
>>> simple_pop_typed(L)
Traceback (most recent call last):
...
IndexError: pop from empty list
"""
return
L
.
pop
()
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode/AttributeNode'
)
def
index_pop
(
L
,
int
i
):
...
...
@@ -68,6 +92,40 @@ def index_pop(L, int i):
"""
return
L
.
pop
(
i
)
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode/AttributeNode'
)
def
index_pop_typed
(
list
L
,
int
i
):
"""
>>> L = list(range(10))
>>> index_pop_typed(L, 2)
2
>>> index_pop_typed(L, -2)
8
>>> L
[0, 1, 3, 4, 5, 6, 7, 9]
>>> index_pop_typed(L, 100)
Traceback (most recent call last):
...
IndexError: pop index out of range
>>> index_pop_typed(L, -100)
Traceback (most recent call last):
...
IndexError: pop index out of range
>>> while L:
... _ = index_pop_typed(L, 0)
>>> L
[]
>>> index_pop_typed(L, 0)
Traceback (most recent call last):
...
IndexError: pop from empty list
"""
return
L
.
pop
(
i
)
@
cython
.
test_fail_if_path_exists
(
'//PythonCapiCallNode'
)
def
crazy_pop
(
L
):
"""
...
...
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