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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
491aa659
Commit
491aa659
authored
Apr 27, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid generating code for 'if' conditions that are known to be False
parent
6d2ccb85
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
10 deletions
+34
-10
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+34
-10
No files found.
Cython/Compiler/Nodes.py
View file @
491aa659
...
...
@@ -3871,18 +3871,36 @@ class IfStatNode(StatNode):
if_clause
.
analyse_expressions
(
env
)
if
self
.
else_clause
:
self
.
else_clause
.
analyse_expressions
(
env
)
# eliminate dead code based on constant condition results
if_clauses
=
[]
condition_result
=
None
for
if_clause
in
self
.
if_clauses
:
condition_result
=
if_clause
.
get_constant_condition_result
()
if
condition_result
!=
False
:
if_clauses
.
append
(
if_clause
)
if
condition_result
==
True
:
# other conditions can no longer apply
self
.
else_clause
=
None
break
self
.
if_clauses
=
if_clauses
# FIXME: if only one active code body is left here, we can
# replace the whole node
def
generate_execution_code
(
self
,
code
):
code
.
mark_pos
(
self
.
pos
)
end_label
=
code
.
new_label
()
for
if_clause
in
self
.
if_clauses
:
if_clause
.
generate_execution_code
(
code
,
end_label
)
if
self
.
else_clause
:
code
.
putln
(
"/*else*/ {"
)
if
self
.
if_clauses
:
end_label
=
code
.
new_label
()
for
if_clause
in
self
.
if_clauses
:
if_clause
.
generate_execution_code
(
code
,
end_label
)
if
self
.
else_clause
:
code
.
putln
(
"/*else*/ {"
)
self
.
else_clause
.
generate_execution_code
(
code
)
code
.
putln
(
"}"
)
code
.
put_label
(
end_label
)
elif
self
.
else_clause
:
self
.
else_clause
.
generate_execution_code
(
code
)
code
.
putln
(
"}"
)
code
.
put_label
(
end_label
)
def
annotate
(
self
,
code
):
for
if_clause
in
self
.
if_clauses
:
if_clause
.
annotate
(
code
)
...
...
@@ -3909,7 +3927,13 @@ class IfClauseNode(Node):
self
.
condition
=
\
self
.
condition
.
analyse_temp_boolean_expression
(
env
)
self
.
body
.
analyse_expressions
(
env
)
def
get_constant_condition_result
(
self
):
if
self
.
condition
.
has_constant_result
():
return
self
.
condition
.
constant_result
else
:
return
None
def
generate_execution_code
(
self
,
code
,
end_label
):
self
.
condition
.
generate_evaluation_code
(
code
)
code
.
putln
(
...
...
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