[pypy-commit] pypy faster-rstruct-2: use @GCBuffer to implement MutableStringBuffer

antocuni pypy.commits at gmail.com
Tue May 16 05:49:03 EDT 2017


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: faster-rstruct-2
Changeset: r91308:967e8af6bfb8
Date: 2017-05-16 11:47 +0200
http://bitbucket.org/pypy/pypy/changeset/967e8af6bfb8/

Log:	use @GCBuffer to implement MutableStringBuffer

diff --git a/rpython/rlib/mutbuffer.py b/rpython/rlib/mutbuffer.py
--- a/rpython/rlib/mutbuffer.py
+++ b/rpython/rlib/mutbuffer.py
@@ -3,9 +3,10 @@
 from rpython.rtyper.lltypesystem.rstr import STR, mallocstr
 from rpython.rtyper.annlowlevel import llstr, hlstr
 from rpython.rlib.objectmodel import specialize
-from rpython.rlib.buffer import Buffer
+from rpython.rlib.buffer import Buffer, GCBuffer
 from rpython.rlib import jit
 
+ at GCBuffer
 class MutableStringBuffer(Buffer):
     """
     A writeable buffer to incrementally fill a string of a fixed size.
@@ -53,11 +54,10 @@
         for i in range(index, index+count):
             self.setitem(i, '\x00')
 
-    @specialize.ll_and_arg(1)
-    def typed_write(self, TP, byte_offset, value):
-        base_ofs = (llmemory.offsetof(STR, 'chars') +
-                    llmemory.itemoffsetof(STR.chars, 0))
-        scale_factor = llmemory.sizeof(lltype.Char)
-        value = lltype.cast_primitive(TP, value)
-        llop.gc_store_indexed(lltype.Void, self.ll_val, byte_offset, value,
-                              scale_factor, base_ofs)
+    @staticmethod
+    def _get_gc_data_offset():
+        return (llmemory.offsetof(STR, 'chars') +
+                llmemory.itemoffsetof(STR.chars, 0))
+
+    def _get_gc_data(self):
+        return lltype.cast_opaque_ptr(llmemory.GCREF, self.ll_val)


More information about the pypy-commit mailing list