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

index eeeaab0ce808b4bf63a3b7bcd049edbbf3c00553..cd44835cb57f95e0a52cec656da2285417ba4631 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -50,6 +50,8 @@ Core and Builtins
 Extension Modules
 -----------------
 
+- Issue #3116:  marshal.dumps() had quadratic behavior for strings > 32Mb.
+
 - Issue #2138: Add factorial() the math module.
 
 - The heapq module does comparisons using LT instead of LE.  This
index 6db46e4f6382b7ace855f326785f364cddf15c87..140192f33bc92a45f09c806a338afdcfc7889db1 100644 (file)
@@ -67,7 +67,7 @@ w_more(int c, WFILE *p)
        size = PyString_Size(p->str);
        newsize = size + size + 1024;
        if (newsize > 32*1024*1024) {
-               newsize = size + 1024*1024;
+               newsize = size + (size >> 3);   /* 12.5% overallocation */
        }
        if (_PyString_Resize(&p->str, newsize) != 0) {
                p->ptr = p->end = NULL;