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
9ecf58c8
Commit
9ecf58c8
authored
Dec 01, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pre-calculate constant loop length when iterating over literal tuples/lists
parent
cc8a670b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+8
-5
tests/run/for_in_iter.py
tests/run/for_in_iter.py
+12
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
9ecf58c8
...
...
@@ -2337,11 +2337,14 @@ class IteratorNode(ExprNode):
def
generate_next_sequence_item
(
self
,
test_name
,
result_name
,
code
):
assert
self
.
counter_cname
,
"internal error: counter_cname temp not prepared"
code
.
putln
(
"if (%s >= Py%s_GET_SIZE(%s)) break;"
%
(
self
.
counter_cname
,
test_name
,
self
.
py_result
()))
final_size
=
'Py%s_GET_SIZE(%s)'
%
(
test_name
,
self
.
py_result
())
if
self
.
sequence
.
is_sequence_constructor
:
item_count
=
len
(
self
.
sequence
.
args
)
if
self
.
sequence
.
mult_factor
is
None
:
final_size
=
item_count
elif
isinstance
(
self
.
sequence
.
mult_factor
.
constant_result
,
(
int
,
long
)):
final_size
=
item_count
*
self
.
sequence
.
mult_factor
.
constant_result
code
.
putln
(
"if (%s >= %s) break;"
%
(
self
.
counter_cname
,
final_size
))
if
self
.
reversed
:
inc_dec
=
'--'
else
:
...
...
tests/run/for_in_iter.py
View file @
9ecf58c8
...
...
@@ -49,6 +49,18 @@ def for_in_literal_list():
l
.
append
(
i
)
return
l
@
cython
.
test_assert_path_exists
(
'//TupleNode//IntNode'
)
@
cython
.
test_fail_if_path_exists
(
'//ListNode//IntNode'
)
def
for_in_literal_mult_list
():
"""
>>> for_in_literal_mult_list()
[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]
"""
l
=
[]
for
i
in
[
1
,
2
,
3
,
4
]
*
3
:
l
.
append
(
i
)
return
l
class
Iterable
(
object
):
"""
>>> for_in_pyiter(Iterable(5))
...
...
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