From: Raymond Hettinger Date: Mon, 16 Jun 2008 01:42:40 +0000 (+0000) Subject: Issue 3116: fix quadratic behavior in marshal.dumps(). X-Git-Tag: v2.6b1~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=305480c9dcec736cba91db62062f75b5ceff9b60;p=python Issue 3116: fix quadratic behavior in marshal.dumps(). --- diff --git a/Misc/NEWS b/Misc/NEWS index eeeaab0ce8..cd44835cb5 100644 --- 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 diff --git a/Python/marshal.c b/Python/marshal.c index 6db46e4f63..140192f33b 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -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;