From 75ee9eb9c60cc85925d2bfe9f92f2b2da81ddefd Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 16 Jun 2008 01:49:18 +0000 Subject: Issue #3116 and #1792: Fix quadratic behavior in marshal.dumps(). --- Python/marshal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Python/marshal.c') 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; } -- cgit v1.2.1