I knew I should have included some psuedo bytecode...<div><br></div><div>Conversely, if you have some code that does something between the if and the continue, you'll have some other code on line 12a and line 12b will be the jump, and the optimizer won't want to remove line 12a anymore.<br>
<div><br clear="all">Eric<br>
<br><br><div class="gmail_quote">On Sun, Jul 3, 2011 at 9:42 AM, Ned Batchelder <span dir="ltr"><<a href="mailto:ned@nedbatchelder.com">ned@nedbatchelder.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<u></u>
<div 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><font color="#888888">
<br>
--Ned.</font><div><div></div><div class="h5"><br>
<br>
<br>
On 7/3/2011 9:09 AM, Eric Henry wrote:
<blockquote 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 href="mailto:_@lvh.cc" target="_blank"><_@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 href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
<a 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>
</div></div></div>
</blockquote></div><br></div></div>