Author: Antonio Cuni <[email protected]>
Branch: faster-rstruct-2
Changeset: r91231:574964807a61
Date: 2017-05-10 18:24 +0200
http://bitbucket.org/pypy/pypy/changeset/574964807a61/

Log:    fix pack_pad

diff --git a/rpython/rlib/rstruct/standardfmttable.py 
b/rpython/rlib/rstruct/standardfmttable.py
--- a/rpython/rlib/rstruct/standardfmttable.py
+++ b/rpython/rlib/rstruct/standardfmttable.py
@@ -21,7 +21,11 @@
 native_is_ieee754 = float.__getformat__('double').startswith('IEEE')
 
 def pack_pad(fmtiter, count):
-    fmtiter.result.append_multiple_char('\x00', count)
+    if fmtiter.needs_zeros:
+        pos = fmtiter.pos
+        for i in range(count):
+            fmtiter.result.setitem(pos+i, '\x00')
+    fmtiter.advance(count)
 
 def pack_char(fmtiter):
     string = fmtiter.accept_str_arg()
diff --git a/rpython/rlib/rstruct/test/test_pack.py 
b/rpython/rlib/rstruct/test/test_pack.py
--- a/rpython/rlib/rstruct/test/test_pack.py
+++ b/rpython/rlib/rstruct/test/test_pack.py
@@ -88,10 +88,8 @@
         self.check('?', False)
 
     def test_pack_pad(self):
-        bigendian = self.endianess == '>'
-        fmtiter = FakeFormatIter(bigendian, None)
-        standardfmttable.pack_pad(fmtiter, 4)
-        s = fmtiter.result.build()
+        s = self.mypack_fn(standardfmttable.pack_pad,
+                           arg=4, value=None, size=4)
         assert s == '\x00'*4
 
     def test_pack_string(self):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to