[Python-checkins] r64292 - python/branches/tlee-ast-optimize/Python/optimize.c
thomas.lee
python-checkins at python.org
Sun Jun 15 15:14:50 CEST 2008
Author: thomas.lee
Date: Sun Jun 15 15:14:49 2008
New Revision: 64292
Log:
While.orelse and For.orelse were not being used in place of their respective bodies in unreachable loops.
Modified:
python/branches/tlee-ast-optimize/Python/optimize.c
Modified: python/branches/tlee-ast-optimize/Python/optimize.c
==============================================================================
--- python/branches/tlee-ast-optimize/Python/optimize.c (original)
+++ python/branches/tlee-ast-optimize/Python/optimize.c Sun Jun 15 15:14:49 2008
@@ -269,13 +269,17 @@
PyObject* test = _expr_constant_value(stmt->v.While.test);
if (test != NULL) {
if (!PyObject_IsTrue(test)) {
- /* XXX: what about orelse? */
- seq = _asdl_seq_replace_with_pass(seq, n, stmt->lineno,
- stmt->col_offset, arena);
+ if (stmt->v.While.orelse != NULL) {
+ seq = _asdl_seq_replace(seq, n, stmt->v.While.orelse,
+ arena);
+ }
+ else {
+ seq = _asdl_seq_replace_with_pass(seq, n, stmt->lineno,
+ stmt->col_offset, arena);
+ }
+ if (seq == NULL)
+ return 0;
}
- if (seq == NULL)
- return 0;
- *seq_ptr = seq;
}
}
/* eliminate unreachable for loops? */
@@ -283,13 +287,16 @@
PyObject* iter = _expr_constant_value(stmt->v.For.iter);
if (iter != NULL) {
if (PyObject_Size(iter) == 0) {
- /* XXX: what about orelse? */
- seq = _asdl_seq_replace_with_pass(seq, n, stmt->lineno,
- stmt->col_offset, arena);
+ if (stmt->v.For.orelse != NULL) {
+ seq = _asdl_seq_replace(seq, n, stmt->v.For.orelse, arena);
+ }
+ else {
+ seq = _asdl_seq_replace_with_pass(seq, n, stmt->lineno,
+ stmt->col_offset, arena);
+ }
+ if (seq == NULL)
+ return 0;
}
- if (seq == NULL)
- return 0;
- *seq_ptr = seq;
}
}
/* eliminate all code after a "return" statement */
@@ -299,9 +306,10 @@
stmt->lineno, stmt->col_offset, arena);
if (seq == NULL)
return 0;
- *seq_ptr = seq;
}
+ *seq_ptr = seq;
+
return 1;
}
More information about the Python-checkins
mailing list