<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
(Enormous hand-waving over significant details below)<br>
<br>
If your code is this:<br>
<br>
10: for item in container:<br>
11: if item.some_condition() or item.some_other():<br>
12: continue<br>
13: item.do_real_stuff()<br>
<br>
Then the generated code looks very crudely something like:<br>
<br>
10a: start iterating container<br>
10b: get next item<br>
11a: if item.some_condition() jump to 12a<br>
11b: if item.some_other() jump to 12a<br>
11c: jump to 13a<br>
12a: jump to 10b<br>
13a: item.do_real_stuff()<br>
13b: jump to 10b<br>
<br>
The peephole optimizer sees that lines 11a and 11b include a jump to
12a, but 12a is an unconditional jump to 10b, so it changes line 11a
and 11b:<br>
<br>
11a: if item.some_condition() jump to 10b<br>
11b: if item.some_other() jump to 10b<br>
<br>
Line 12 is now never executed.<br>
<br>
--Ned.<br>
<br>
<br>
On 7/3/2011 9:09 AM, Eric Henry wrote:
<blockquote
cite="mid:CAJS6nNN1KSgj=OpWY8yfWmFncTVMjbViBChiUk6QL9O4Xo34mw@mail.gmail.com"
type="cite">Right, but the point is that you're not doing anything
else if the condition is true.
<div><br>
</div>
<div>I can't say for sure, but it would seem that it could easily
convert the if ... continue into a "branch on equal" type
bytecode. What happens if you have a print statement before the
continue?<br>
<div><br clear="all">
Eric<br>
<br>
<br>
<div class="gmail_quote">On Sun, Jul 3, 2011 at 6:41 AM,
Laurens Van Houtven <span dir="ltr"><a class="moz-txt-link-rfc2396E" href="mailto:_@lvh.cc"><_@lvh.cc></a></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
Hang on. This appears to be for *unconditional* jumps. My
jump isn't unconditional, it's "if snr is None or prn is
None:". How does that get optimized away? Where's the
always-true condition? "prn is None or snr is None" is
certainly not always true, in fact, that's the exception,
not the norm.<br>
<br>
_______________________________________________<br>
testing-in-python mailing list<br>
<a moz-do-not-send="true"
href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a moz-do-not-send="true"
href="http://lists.idyll.org/listinfo/testing-in-python"
target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
</body>
</html>