[pypy-commit] pypy list-strategies: don't use the JIT strslice optimization if some of the characters are in an unknown state with regards to whether they're initialized
alex_gaynor
noreply at buildbot.pypy.org
Wed Nov 2 22:14:29 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: list-strategies
Changeset: r48674:30af37ca7941
Date: 2011-11-02 17:14 -0400
http://bitbucket.org/pypy/pypy/changeset/30af37ca7941/
Log: don't use the JIT strslice optimization if some of the characters
are in an unknown state with regards to whether they're initialized
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
@@ -4225,6 +4225,27 @@
"""
self.optimize_strunicode_loop(ops, expected)
+ def test_str_slice_plain_virtual(self):
+ ops = """
+ []
+ p0 = newstr(11)
+ copystrcontent(s"hello world", p0, 0, 0, 11)
+ p1 = call(0, p0, 0, 5, descr=strslicedescr)
+ finish(p1)
+ """
+ expected = """
+ []
+ p0 = newstr(11)
+ copystrcontent(s"hello world", p0, 0, 0, 11)
+ # Eventually this should just return s"hello", but ATM this test is
+ # just verifying that it doesn't return "\0\0\0\0\0", so being
+ # slightly underoptimized is ok.
+ p1 = newstr(5)
+ copystrcontent(p0, p1, 0, 0, 5)
+ finish(p1)
+ """
+ self.optimize_strunicode_loop(ops, expected)
+
# ----------
def optimize_strunicode_loop_extradescrs(self, ops, optops):
class FakeCallInfoCollection:
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
@@ -505,11 +505,17 @@
#
if (isinstance(vstr, VStringPlainValue) and vstart.is_constant()
and vstop.is_constant()):
- # slicing with constant bounds of a VStringPlainValue
- value = self.make_vstring_plain(op.result, op, mode)
- value.setup_slice(vstr._chars, vstart.box.getint(),
- vstop.box.getint())
- return True
+ # slicing with constant bounds of a VStringPlainValue, if any of
+ # the characters is unitialized we don't do this special slice, we
+ # do the regular copy contents.
+ for i in range(vstart.box.getint(), vstop.box.getint()):
+ if vstr.getitem(i) is optimizer.CVAL_UNINITIALIZED_ZERO:
+ break
+ else:
+ value = self.make_vstring_plain(op.result, op, mode)
+ value.setup_slice(vstr._chars, vstart.box.getint(),
+ vstop.box.getint())
+ return True
#
vstr.ensure_nonnull()
lengthbox = _int_sub(self, vstop.force_box(self),
More information about the pypy-commit
mailing list