[pypy-svn] r16062 - pypy/dist/pypy/module/marshal

tismer at codespeak.net tismer at codespeak.net
Sun Aug 14 18:27:20 CEST 2005


Author: tismer
Date: Sun Aug 14 18:27:19 2005
New Revision: 16062

Modified:
   pypy/dist/pypy/module/marshal/interp_marshal.py
Log:
tested a different dumps buffering scheme, using
a list of chars instead of strings.
This seems to be a very good thing, marshalling
got almost twice as fast, about to reach loads
speed.

Side note: compared to compiled PyPy, CPython's marshal
is very much slower for the test case
marshal.dumps(1L << 100000000)
Can it be that they have no good buffer allocation, here?
For loads, CPython is about 20 times faster ATM.


Modified: pypy/dist/pypy/module/marshal/interp_marshal.py
==============================================================================
--- pypy/dist/pypy/module/marshal/interp_marshal.py	(original)
+++ pypy/dist/pypy/module/marshal/interp_marshal.py	Sun Aug 14 18:27:19 2005
@@ -95,7 +95,7 @@
 
 
 class StringWriter(_BaseWriter):
-    # actually we are writing to a stringlist
+    # actually we are writing to a char list
     def __init__(self):
         self.buflis = []
 
@@ -107,20 +107,24 @@
 
 
 class StringWriter(_BaseWriter):
-    # actually we are writing to a stringlist
+    # actually we are writing to a char list
     def __init__(self):
-        self.buflis = ['']
+        self.buflis = [chr(0)] * 128
         self.bufpos = 0
 
     def write(self, data):
         # append is not (yet) efficient, so we do our own allocation
         #self.buflis.append(data)
         pos = self.bufpos
-        if not pos & (pos-1) and pos > 0:
-            # power of two, double the buffer
-            self.buflis += self.buflis
-        self.buflis[pos] = data
-        self.bufpos = pos + 1
+        lng = len(data)
+        newpos = pos + lng
+	while len(self.buflis) < newpos:
+            self.buflis = self.buflis + self.buflis
+        idx = 0
+        while idx < lng:
+            self.buflis[pos + idx] = data[idx]
+            idx += 1
+        self.bufpos = newpos
 
     def get_value(self):
         return ''.join(self.buflis[:self.bufpos])



More information about the Pypy-commit mailing list