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
bd4658c4
Commit
bd4658c4
authored
Aug 17, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimise "range(enum)" (currently infers enum type for loop variable - worth reconsidering).
parent
99085010
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
1 deletion
+23
-1
CHANGES.rst
CHANGES.rst
+2
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+1
-1
tests/run/for_in_range_T372.pyx
tests/run/for_in_range_T372.pyx
+20
-0
No files found.
CHANGES.rst
View file @
bd4658c4
...
...
@@ -31,6 +31,8 @@ Features added
Bugs fixed
----------
* Loops over ``range(enum)`` were not converted into C for-loops.
* Compile time ``DEF`` assignments were evaluated even when they occur inside of
falsy ``IF`` blocks. (Github issue #1796)
...
...
Cython/Compiler/Optimize.py
View file @
bd4658c4
...
...
@@ -259,7 +259,7 @@ class IterationTransform(Visitor.EnvTransform):
return
self
.
_transform_reversed_iteration
(
node
,
iterator
)
# range() iteration?
if
Options
.
convert_range
and
node
.
target
.
type
.
is_int
:
if
Options
.
convert_range
and
(
node
.
target
.
type
.
is_int
or
node
.
target
.
type
.
is_enum
)
:
if
iterator
.
self
is
None
and
function
.
is_name
and
\
function
.
entry
and
function
.
entry
.
is_builtin
and
\
function
.
name
in
(
'range'
,
'xrange'
):
...
...
tests/run/for_in_range_T372.pyx
View file @
bd4658c4
...
...
@@ -117,3 +117,23 @@ def test_return():
return
i
,
n
print
return
"FAILED!"
ctypedef
enum
RangeEnum
:
EnumValue1
EnumValue2
EnumValue3
@
cython
.
test_assert_path_exists
(
"//ForFromStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//ForInStatNode"
)
def
test_enum_range
():
"""
# NOTE: it's not entirely clear that this is the expected behaviour, but that's how it currently is.
>>> test_enum_range()
'RangeEnum'
"""
cdef
RangeEnum
n
=
EnumValue3
for
i
in
range
(
n
):
assert
cython
.
typeof
(
i
)
==
"RangeEnum"
,
cython
.
typeof
(
i
)
return
cython
.
typeof
(
i
)
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