summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-06-16 01:49:18 +0000
committerRaymond Hettinger <python@rcn.com>2008-06-16 01:49:18 +0000
commit64626ade7074929362acb8b488ad3b513e9a35f5 (patch)
tree4a4ec2c649465a71796340950ced36d9f129e2a1 /Python
parent9aa9fec0d5bc1450a77e7c35e62bd132c610766d (diff)
downloadcpython-64626ade7074929362acb8b488ad3b513e9a35f5.tar.gz
Issue #3116 and #1792: Fix quadratic behavior in marshal.dumps().
Diffstat (limited to 'Python')
-rw-r--r--Python/marshal.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index 897c15ec8a..c305bbe47c 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -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;
}