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
Gwenaël Samain
cython
Commits
8e3915f6
Commit
8e3915f6
authored
Apr 29, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code cleanup for if-const dead code removal
parent
e80d0678
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
13 deletions
+11
-13
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+11
-13
No files found.
Cython/Compiler/Optimize.py
View file @
8e3915f6
...
...
@@ -2582,23 +2582,21 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
self
.
visitchildren
(
node
)
# eliminate dead code based on constant condition results
if_clauses
=
[]
condition_result
=
None
for
if_clause
in
node
.
if_clauses
:
condition_result
=
if_clause
.
get_constant_condition_result
()
# condition_result is True, False or None (unknown)
if
condition_result
!=
False
:
if
condition_result
is
None
:
# unknown result => normal runtime evaluation
if_clauses
.
append
(
if_clause
)
if
condition_result
==
True
:
# other conditions can no longer apply
node
.
else_clause
=
None
break
elif
condition_result
==
True
:
# subsequent clauses can safely be dropped
node
.
else_clause
=
if_clause
.
body
break
else
:
assert
condition_result
==
False
if
not
if_clauses
:
return
node
.
else_clause
# if None, deletes the node completely
elif
len
(
if_clauses
)
==
1
and
condition_result
==
True
:
return
if_clauses
[
0
].
body
else
:
node
.
if_clauses
=
if_clauses
return
node
return
node
.
else_clause
node
.
if_clauses
=
if_clauses
return
node
# in the future, other nodes can have their own handler method here
# that can replace them with a constant result node
...
...
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