[pypy-svn] r78824 - in pypy/branch/fast-forward/pypy: interpreter module/__builtin__ module/__builtin__/test

arigo at codespeak.net arigo at codespeak.net
Sun Nov 7 17:34:05 CET 2010


Author: arigo
Date: Sun Nov  7 17:34:04 2010
New Revision: 78824

Modified:
   pypy/branch/fast-forward/pypy/interpreter/buffer.py
   pypy/branch/fast-forward/pypy/module/__builtin__/__init__.py
   pypy/branch/fast-forward/pypy/module/__builtin__/operation.py
   pypy/branch/fast-forward/pypy/module/__builtin__/test/test_buffer.py
Log:
Attempt to kill the W_Memoryview class, and just use buffers.
Doing so is a lot more efficient, because it will select the
right subclass of Buffer when constructing it.

Also rename memoryview.to_bytes() to memoryview.tobytes(),
according to the CPython API documentation.

This actually adds tobytes() as a method on all buffer objects.
I suppose it's fine.


Modified: pypy/branch/fast-forward/pypy/interpreter/buffer.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/buffer.py	(original)
+++ pypy/branch/fast-forward/pypy/interpreter/buffer.py	Sun Nov  7 17:34:04 2010
@@ -207,6 +207,7 @@
     __mul__ = interp2app(Buffer.descr_mul),
     __rmul__ = interp2app(Buffer.descr_mul),
     __repr__ = interp2app(Buffer.descr_repr),
+    tobytes = interp2app(Buffer.descr_str),
     )
 Buffer.typedef.acceptable_as_base_class = False
 

Modified: pypy/branch/fast-forward/pypy/module/__builtin__/__init__.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/__builtin__/__init__.py	(original)
+++ pypy/branch/fast-forward/pypy/module/__builtin__/__init__.py	Sun Nov  7 17:34:04 2010
@@ -53,7 +53,7 @@
         'bytes'         : '(space.w_str)',
         'unicode'       : '(space.w_unicode)',
         'buffer'        : 'operation.W_Buffer',
-        'memoryview'    : 'operation.W_Memoryview',
+        'memoryview'    : 'operation.W_Buffer',
 
         'file'          : 'state.get(space).w_file',
         'open'          : 'state.get(space).w_file',

Modified: pypy/branch/fast-forward/pypy/module/__builtin__/operation.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/__builtin__/operation.py	(original)
+++ pypy/branch/fast-forward/pypy/module/__builtin__/operation.py	Sun Nov  7 17:34:04 2010
@@ -16,23 +16,6 @@
 
 W_Buffer = buffer.Buffer
 
-class W_Memoryview(buffer.StringLikeBuffer):
-    @unwrap_spec(ObjSpace, W_Root, W_Root)
-    def descr_new(space, w_subtype, w_object):
-        self = space.allocate_instance(W_Memoryview, w_subtype)
-        buffer.StringLikeBuffer.__init__(self, space, w_object)
-        return space.wrap(self)
-
-    @unwrap_spec('self', ObjSpace)
-    def to_bytes_w(self, space):
-        return space.wrap(self.as_str())
-
-W_Memoryview.typedef = TypeDef(
-    "memoryview", W_Buffer.typedef,
-    __new__=interp2app(W_Memoryview.descr_new.im_func),
-    to_bytes=interp2app(W_Memoryview.to_bytes_w),
-    )
-
 def abs(space, w_val):
     "abs(number) -> number\n\nReturn the absolute value of the argument."
     return space.abs(w_val)

Modified: pypy/branch/fast-forward/pypy/module/__builtin__/test/test_buffer.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/__builtin__/test/test_buffer.py	(original)
+++ pypy/branch/fast-forward/pypy/module/__builtin__/test/test_buffer.py	Sun Nov  7 17:34:04 2010
@@ -163,6 +163,6 @@
 class AppTestMemoryview:
     def test_basic(self):
         v = memoryview("abc")
-        assert v.to_bytes() == "abc"
+        assert v.tobytes() == "abc"
         assert len(v) == 3
         assert list(v) == ['a', 'b', 'c']



More information about the Pypy-commit mailing list