Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(19)

Unified Diff: Lib/test/test_dis.py

Issue 20103: http://bugs.python.org/issue2459 -- speed up loops SVN Base: http://svn.python.org/view/*checkout*/python/trunk/
Patch Set: Created 9 months, 1 week ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side by-side-diff with in-line comments
Download patch
Index: Lib/test/test_dis.py
===================================================================
--- Lib/test/test_dis.py (revision 70087)
+++ Lib/test/test_dis.py (working copy)
@@ -22,6 +22,33 @@
_f.func_code.co_firstlineno + 2)
+def loop(a):
+ while a > 0:
+ a -= 1
+ return a
+
+dis_loop = """\
+%3d 0 SETUP_LOOP 26 (to 29)
+ 3 JUMP_FORWARD 10 (to 16)
+
+%3d >> 6 LOAD_FAST 0 (a)
+ 9 LOAD_CONST 1 (1)
+ 12 INPLACE_SUBTRACT
+ 13 STORE_FAST 0 (a)
+
+%3d >> 16 LOAD_FAST 0 (a)
+ 19 LOAD_CONST 2 (0)
+ 22 COMPARE_OP 4 (>)
+ 25 POP_JUMP_IF_TRUE 6
+ 28 POP_BLOCK
+
+%3d >> 29 LOAD_FAST 0 (a)
+ 32 RETURN_VALUE
+"""%(loop.func_code.co_firstlineno + 1,
+ loop.func_code.co_firstlineno + 2,
+ loop.func_code.co_firstlineno + 1,
+ loop.func_code.co_firstlineno + 3)
+
def bug708901():
for res in range(1,
10):
@@ -35,16 +62,14 @@
%-4d 9 LOAD_CONST 2 (10)
12 CALL_FUNCTION 2
15 GET_ITER
- >> 16 FOR_ITER 6 (to 25)
- 19 STORE_FAST 0 (res)
-
- %-4d 22 JUMP_ABSOLUTE 16
- >> 25 POP_BLOCK
+ 16 JUMP_FORWARD 3 (to 22)
+ >> 19 STORE_FAST 0 (res)
+ >> 22 FOR_ITER 19
+ 25 POP_BLOCK
>> 26 LOAD_CONST 0 (None)
29 RETURN_VALUE
"""%(bug708901.func_code.co_firstlineno + 1,
- bug708901.func_code.co_firstlineno + 2,
- bug708901.func_code.co_firstlineno + 3)
+ bug708901.func_code.co_firstlineno + 2)
def bug1333982(x=[]):
@@ -59,13 +84,13 @@
9 BUILD_LIST 0
12 LOAD_FAST 0 (x)
15 GET_ITER
- >> 16 FOR_ITER 12 (to 31)
- 19 STORE_FAST 1 (s)
+ 16 JUMP_FORWARD 9 (to 28)
+ >> 19 STORE_FAST 1 (s)
22 LOAD_FAST 1 (s)
25 LIST_APPEND 2
- 28 JUMP_ABSOLUTE 16
+ >> 28 FOR_ITER 19
- %-4d >> 31 LOAD_CONST 2 (1)
+ %-4d 31 LOAD_CONST 2 (1)
34 BINARY_ADD
35 RAISE_VARARGS 2
@@ -116,6 +141,9 @@
def test_dis(self):
self.do_disassembly_test(_f, dis_f)
+ def test_lineno_goes_backwards_in_loop(self):
+ self.do_disassembly_test(loop, dis_loop)
+
def test_bug_708901(self):
self.do_disassembly_test(bug708901, dis_bug708901)

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497