Author: Maciej Fijalkowski <[email protected]>
Branch:
Changeset: r49583:0bdcf803c0fd
Date: 2011-11-20 18:09 +0200
http://bitbucket.org/pypy/pypy/changeset/0bdcf803c0fd/
Log: improve the list-comprehension-operation optimization to work for
slightly more advanced cases as well
diff --git a/pypy/translator/simplify.py b/pypy/translator/simplify.py
--- a/pypy/translator/simplify.py
+++ b/pypy/translator/simplify.py
@@ -697,10 +697,12 @@
if op.opname == 'getattr' and op.args[1] == c_append:
vlist = variable_families.find_rep(op.args[0])
if vlist in newlist_v:
- op2 = block.operations[i+1]
- if (op2.opname == 'simple_call' and len(op2.args) == 2
- and op2.args[0] is op.result):
- append_v.append((op.args[0], op.result, block))
+ for j in range(i + 1, len(block.operations)):
+ op2 = block.operations[j]
+ if (op2.opname == 'simple_call' and len(op2.args) == 2
+ and op2.args[0] is op.result):
+ append_v.append((op.args[0], op.result, block))
+ break
if not append_v:
return
detector = ListComprehensionDetector(graph, loops, newlist_v,
diff --git a/pypy/translator/test/test_simplify.py
b/pypy/translator/test/test_simplify.py
--- a/pypy/translator/test/test_simplify.py
+++ b/pypy/translator/test/test_simplify.py
@@ -317,6 +317,12 @@
return new_l
self.check(f, {
+ 'hint': 2,
+ 'newlist': 1,
+ 'iter': 1,
+ 'next': 1,
+ 'getattr': 1,
+ 'simple_call': 3,
})
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit