Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r48761:98bf21b80fc5 Date: 2011-11-04 20:56 +0100 http://bitbucket.org/pypy/pypy/changeset/98bf21b80fc5/
Log: Another case: strgetitem on a VStringConcatValue can be resolved if we know statically on which half of the two-parts string it is done. Could be improved in theory by using intbounds analysis... diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py @@ -4123,6 +4123,38 @@ """ self.optimize_strunicode_loop(ops, expected) + def test_str_concat_constant_lengths(self): + ops = """ + [i0] + p0 = newstr(1) + strsetitem(p0, 0, i0) + p1 = newstr(0) + p2 = call(0, p0, p1, descr=strconcatdescr) + i1 = call(0, p2, p0, descr=strequaldescr) + finish(i1) + """ + expected = """ + [i0] + finish(1) + """ + self.optimize_strunicode_loop(ops, expected) + + def test_str_concat_constant_lengths_2(self): + ops = """ + [i0] + p0 = newstr(0) + p1 = newstr(1) + strsetitem(p1, 0, i0) + p2 = call(0, p0, p1, descr=strconcatdescr) + i1 = call(0, p2, p1, descr=strequaldescr) + finish(i1) + """ + expected = """ + [i0] + finish(1) + """ + self.optimize_strunicode_loop(ops, expected) + def test_str_slice_1(self): ops = """ [p1, i1, i2] @@ -4883,6 +4915,27 @@ def test_plain_virtual_string_copy_content(self): ops = """ + [i1] + p0 = newstr(6) + copystrcontent(s"hello!", p0, 0, 0, 6) + p1 = call(0, p0, s"abc123", descr=strconcatdescr) + i0 = strgetitem(p1, i1) + finish(i0) + """ + expected = """ + [i1] + p0 = newstr(6) + copystrcontent(s"hello!", p0, 0, 0, 6) + p1 = newstr(12) + copystrcontent(p0, p1, 0, 0, 6) + copystrcontent(s"abc123", p1, 0, 6, 6) + i0 = strgetitem(p1, i1) + finish(i0) + """ + self.optimize_strunicode_loop(ops, expected) + + def test_plain_virtual_string_copy_content_2(self): + ops = """ [] p0 = newstr(6) copystrcontent(s"hello!", p0, 0, 0, 6) @@ -4894,10 +4947,7 @@ [] p0 = newstr(6) copystrcontent(s"hello!", p0, 0, 0, 6) - p1 = newstr(12) - copystrcontent(p0, p1, 0, 0, 6) - copystrcontent(s"abc123", p1, 0, 6, 6) - i0 = strgetitem(p1, 0) + i0 = strgetitem(p0, 0) finish(i0) """ self.optimize_strunicode_loop(ops, expected) diff --git a/pypy/jit/metainterp/optimizeopt/vstring.py b/pypy/jit/metainterp/optimizeopt/vstring.py --- a/pypy/jit/metainterp/optimizeopt/vstring.py +++ b/pypy/jit/metainterp/optimizeopt/vstring.py @@ -451,6 +451,17 @@ if result is not None: return result # + if isinstance(value, VStringConcatValue) and vindex.is_constant(): + len1box = value.left.getstrlen(self, mode) + if isinstance(len1box, ConstInt): + index = vindex.box.getint() + len1 = len1box.getint() + if index < len1: + return self.strgetitem(value.left, vindex, mode) + else: + vindex = optimizer.ConstantValue(ConstInt(index - len1)) + return self.strgetitem(value.right, vindex, mode) + # resbox = _strgetitem(self, value.force_box(self), vindex.force_box(self), mode) return self.getvalue(resbox) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit