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
Boxiang Sun
cython
Commits
4cfaa9f6
Commit
4cfaa9f6
authored
Mar 11, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
strip down while-loops with constant condition
parent
d2ac07b1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+9
-0
tests/run/constant_folding.py
tests/run/constant_folding.py
+42
-0
No files found.
Cython/Compiler/Optimize.py
View file @
4cfaa9f6
...
@@ -3241,6 +3241,15 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
...
@@ -3241,6 +3241,15 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
node
.
iterator
.
sequence
=
sequence
.
as_tuple
()
node
.
iterator
.
sequence
=
sequence
.
as_tuple
()
return
node
return
node
def
visit_WhileStatNode
(
self
,
node
):
self
.
visitchildren
(
node
)
if
node
.
condition
.
has_constant_result
():
if
node
.
condition
.
constant_result
:
node
.
else_clause
=
None
else
:
return
node
.
else_clause
return
node
def
_find_genexpr_yield_stat
(
self
,
node
):
def
_find_genexpr_yield_stat
(
self
,
node
):
body_node_types
=
(
Nodes
.
ForInStatNode
,
Nodes
.
IfStatNode
)
body_node_types
=
(
Nodes
.
ForInStatNode
,
Nodes
.
IfStatNode
)
while
isinstance
(
node
,
body_node_types
):
while
isinstance
(
node
,
body_node_types
):
...
...
tests/run/constant_folding.py
View file @
4cfaa9f6
...
@@ -143,3 +143,45 @@ def str_in_and_not_in():
...
@@ -143,3 +143,45 @@ def str_in_and_not_in():
"""
"""
if
'a'
in
'abc'
and
'b'
in
'abc'
and
'c'
in
'abc'
and
'd'
not
in
'abc'
:
return
True
if
'a'
in
'abc'
and
'b'
in
'abc'
and
'c'
in
'abc'
and
'd'
not
in
'abc'
:
return
True
else
:
return
False
else
:
return
False
@
cython
.
test_fail_if_path_exists
(
"//WhileStatNode"
,
)
def
while_false
():
"""
>>> while_false()
"""
while
1
==
0
:
return
False
@
cython
.
test_fail_if_path_exists
(
"//WhileStatNode"
,
)
def
while_false_else
():
"""
>>> while_false_else()
True
"""
while
1
==
0
:
return
False
else
:
return
True
@
cython
.
test_fail_if_path_exists
(
"//WhileStatNode//PrintStatNode"
,
)
@
cython
.
test_assert_path_exists
(
"//WhileStatNode"
,
)
def
while_true
():
"""
>>> while_true()
True
"""
while
1
==
1
:
return
True
else
:
print
(
"FAIL"
)
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