[pypy-commit] pypy PyBuffer: Optimise the common case of slicing a SimpleBuffer (fixes #2516?)
rlamy
pypy.commits at gmail.com
Thu Apr 20 23:11:58 EDT 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: PyBuffer
Changeset: r91108:dce1ad161087
Date: 2017-04-21 04:11 +0100
http://bitbucket.org/pypy/pypy/changeset/dce1ad161087/
Log: Optimise the common case of slicing a SimpleBuffer (fixes #2516?)
diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py
--- a/pypy/objspace/std/memoryobject.py
+++ b/pypy/objspace/std/memoryobject.py
@@ -5,7 +5,7 @@
from rpython.rlib.objectmodel import compute_hash
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.buffer import PyBuffer, SubBuffer
+from pypy.interpreter.buffer import PyBuffer, SimpleBuffer, SubBuffer
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import interp2app
from pypy.interpreter.typedef import TypeDef, GetSetProperty, make_weakref_descr
@@ -166,7 +166,10 @@
raise TypeError("memoryview: invalid slice key")
def new_slice(self, start, stop, step, slicelength, dim):
- sliced = BufferSlice(self.buf, start, step, slicelength)
+ if step == 1 and isinstance(self.buf, SimpleBuffer):
+ sliced = SimpleBuffer(SubBuffer(self.buf.data, start, slicelength))
+ else:
+ sliced = BufferSlice(self.buf, start, step, slicelength)
return W_MemoryView(sliced)
def init_len(self):
More information about the pypy-commit
mailing list