]> granicus.if.org Git - python/commitdiff
Issue #3116 and #1792: Fix quadratic behavior in marshal.dumps().
authorRaymond Hettinger <python@rcn.com>
Mon, 16 Jun 2008 01:49:18 +0000 (01:49 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 16 Jun 2008 01:49:18 +0000 (01:49 +0000)
Misc/NEWS
Python/marshal.c

index 6363f80630d6ffc2bfb01019331b3b22b3812348..cdc3f9c748dd0075d03c46458090e02aa62083a0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -48,6 +48,8 @@ Core and builtins
 Library
 -------
 
+- Issue #3116 and #1792:  Fix quadratic behavior in marshal.dumps().
+
 - Issue #2682: ctypes callback functions no longer contain a cyclic
   reference to themselves.
 
index 897c15ec8ad26424734f43eb3fe1a4ea22ce29e5..c305bbe47c75e04b43aa0f0cf38a2e87b6b36546 100644 (file)
@@ -65,7 +65,10 @@ w_more(int c, WFILE *p)
        if (p->str == NULL)
                return; /* An error already occurred */
        size = PyString_Size(p->str);
-       newsize = size + 1024;
+       newsize = size + size + 1024;
+       if (newsize > 32*1024*1024) {
+               newsize = size + (size >> 3);   /* 12.5% overallocation */
+       }
        if (_PyString_Resize(&p->str, newsize) != 0) {
                p->ptr = p->end = NULL;
        }