Commit 8ef81da5 authored by Stefan Behnel's avatar Stefan Behnel

support non-trivial counter targets for enumerate() loop optimisation

parent cae65475
......@@ -523,9 +523,6 @@ class IterationTransform(Visitor.EnvTransform):
if len(targets) != 2:
# leave this untouched for now
return node
if not isinstance(targets[0], ExprNodes.NameNode):
# leave this untouched for now
return node
enumerate_target, iterable_target = targets
counter_type = enumerate_target.type
......
......@@ -14,6 +14,19 @@ def go_py_enumerate():
for i,k in enumerate(range(1,5)):
print i, k
@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
def py_enumerate_list_index_target():
"""
>>> py_enumerate_list_index_target()
[0] 1
[1] 2
[2] 3
[3] 4
"""
target = [None]
for target[0],k in enumerate(range(1,5)):
print target, k
@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
def go_py_enumerate_start():
"""
......@@ -39,6 +52,20 @@ def go_c_enumerate():
for i,k in enumerate(range(1,5)):
print i, k
@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
def c_enumerate_carray_target():
"""
>>> c_enumerate_carray_target()
0 1
1 2
2 3
3 4
"""
cdef int k
cdef int i[1]
for i[0],k in enumerate(range(1,5)):
print i[0], k
@cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
def go_c_enumerate_step():
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment