Author: Antonio Cuni <[email protected]>
Branch: faster-rstruct-2
Changeset: r91283:00ab2f34b4af
Date: 2017-05-13 15:14 +0200
http://bitbucket.org/pypy/pypy/changeset/00ab2f34b4af/

Log:    pass an external wbuf to PackFormatIterator

diff --git a/pypy/module/struct/formatiterator.py 
b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -2,7 +2,6 @@
                                       maxint, intmask)
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import specialize
-from rpython.rlib.mutbuffer import MutableStringBuffer
 from rpython.rlib.rstruct.error import StructError
 from rpython.rlib.rstruct.formatiterator import FormatIterator
 
@@ -10,12 +9,12 @@
 
 
 class PackFormatIterator(FormatIterator):
-    def __init__(self, space, args_w, size):
+    def __init__(self, space, wbuf, args_w):
         self.space = space
         self.args_w = args_w
         self.args_index = 0
         self.pos = 0
-        self.wbuf = MutableStringBuffer(size)
+        self.wbuf = wbuf
 
     def advance(self, count):
         self.pos += count
diff --git a/pypy/module/struct/interp_struct.py 
b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -1,5 +1,6 @@
 from rpython.rlib import jit
 from rpython.rlib.buffer import SubBuffer
+from rpython.rlib.mutbuffer import MutableStringBuffer
 from rpython.rlib.rstruct.error import StructError, StructOverflowError
 from rpython.rlib.rstruct.formatiterator import CalcSizeFormatIterator
 
@@ -41,15 +42,16 @@
 def _pack(space, format, args_w):
     """Return string containing values v1, v2, ... packed according to fmt."""
     size = _calcsize(space, format)
-    fmtiter = PackFormatIterator(space, args_w, size)
+    wbuf = MutableStringBuffer(size)
+    fmtiter = PackFormatIterator(space, wbuf, args_w)
     try:
         fmtiter.interpret(format)
     except StructOverflowError as e:
         raise OperationError(space.w_OverflowError, space.newtext(e.msg))
     except StructError as e:
         raise OperationError(get_error(space), space.newtext(e.msg))
-    assert fmtiter.pos == fmtiter.wbuf.getlength(), 'missing .advance() or 
wrong calcsize()'
-    return fmtiter.wbuf.finish()
+    assert fmtiter.pos == wbuf.getlength(), 'missing .advance() or wrong 
calcsize()'
+    return wbuf.finish()
 
 
 @unwrap_spec(format='text')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to