Author: Antonio Cuni <[email protected]>
Branch: faster-rstruct-2
Changeset: r91209:a5ddf413daad
Date: 2017-05-09 18:43 +0200
http://bitbucket.org/pypy/pypy/changeset/a5ddf413daad/

Log:    use the new RawBuffer as a base class for ArrayBuffer: as a
        consequence, now it automatically gets the benefits of the fastpath
        in rstruct :)

diff --git a/pypy/module/array/interp_array.py 
b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -1,5 +1,5 @@
 from rpython.rlib import jit, rgc
-from rpython.rlib.buffer import Buffer
+from rpython.rlib.buffer import RawBuffer
 from rpython.rlib.objectmodel import keepalive_until_here
 from rpython.rlib.rarithmetic import ovfcheck, widen
 from rpython.rlib.unroll import unrolling_iterable
@@ -796,7 +796,7 @@
     v.typecode = k
 unroll_typecodes = unrolling_iterable(types.keys())
 
-class ArrayBuffer(Buffer):
+class ArrayBuffer(RawBuffer):
     _immutable_ = True
 
     def __init__(self, array, readonly):
diff --git a/pypy/module/struct/test/test_struct.py 
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -480,7 +480,7 @@
 
 
 class AppTestFastPath(object):
-    spaceconfig = dict(usemodules=['struct', '__pypy__'])
+    spaceconfig = dict(usemodules=['array', 'struct', '__pypy__'])
 
     def setup_class(cls):
         from rpython.rlib.rstruct import standardfmttable
@@ -509,6 +509,12 @@
         assert self.struct.unpack_from("ii", buf, offset) == (42, 43)
 
     def test_unpack_bytearray(self):
-        buf = self.struct.pack("iii", 0, 42, 43)
-        buf = bytearray(buf)
+        data = self.struct.pack("iii", 0, 42, 43)
+        buf = bytearray(data)
         assert self.struct.unpack("iii", buf) == (0, 42, 43)
+
+    def test_unpack_array(self):
+        import array
+        data = self.struct.pack("iii", 0, 42, 43)
+        buf = array.array('c', data)
+        assert self.struct.unpack("iii", buf) == (0, 42, 43)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to