[Python-checkins] r64304 - in python/branches/release25-maint: Misc/NEWS Python/marshal.c

raymond.hettinger python-checkins at python.org
Mon Jun 16 03:49:18 CEST 2008


Author: raymond.hettinger
Date: Mon Jun 16 03:49:18 2008
New Revision: 64304

Log:
Issue #3116 and #1792: Fix quadratic behavior in marshal.dumps().

Modified:
   python/branches/release25-maint/Misc/NEWS
   python/branches/release25-maint/Python/marshal.c

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Mon Jun 16 03:49:18 2008
@@ -48,6 +48,8 @@
 Library
 -------
 
+- Issue #3116 and #1792:  Fix quadratic behavior in marshal.dumps().
+
 - Issue #2682: ctypes callback functions no longer contain a cyclic
   reference to themselves.
 

Modified: python/branches/release25-maint/Python/marshal.c
==============================================================================
--- python/branches/release25-maint/Python/marshal.c	(original)
+++ python/branches/release25-maint/Python/marshal.c	Mon Jun 16 03:49:18 2008
@@ -65,7 +65,10 @@
 	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;
 	}


More information about the Python-checkins mailing list