[pypy-commit] pypy default: remove loop from StringBuffer.getslice

bdkearns noreply at buildbot.pypy.org
Sun May 4 20:25:00 CEST 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r71262:5cf4ae8fccac
Date: 2014-05-04 12:48 -0400
http://bitbucket.org/pypy/pypy/changeset/5cf4ae8fccac/

Log:	remove loop from StringBuffer.getslice

diff --git a/rpython/rlib/buffer.py b/rpython/rlib/buffer.py
--- a/rpython/rlib/buffer.py
+++ b/rpython/rlib/buffer.py
@@ -61,7 +61,7 @@
         if step == 1:
             assert 0 <= start <= stop
             return self.value[start:stop]
-        return "".join([self.value[start + i*step] for i in xrange(size)])
+        return Buffer.getslice(self, start, stop, step, size)
 
 
 class SubBuffer(Buffer):
diff --git a/rpython/rlib/test/test_buffer.py b/rpython/rlib/test/test_buffer.py
--- a/rpython/rlib/test/test_buffer.py
+++ b/rpython/rlib/test/test_buffer.py
@@ -6,4 +6,5 @@
     assert buf.getitem(4) == 'o'
     assert buf.getlength() == 11
     assert buf.getslice(1, 6, 1, 5) == 'ello '
+    assert buf.getslice(1, 6, 2, 3) == 'el '
     assert buf.as_str() == 'hello world'


More information about the pypy-commit mailing list