diff -r fafe20297927 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Thu Nov 07 00:53:56 2013 +0100 +++ b/Objects/unicodeobject.c Thu Nov 07 09:43:39 2013 +0100 @@ -13092,6 +13092,13 @@ int _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer, Py_ssize_t length, Py_UCS4 maxchar) { +#ifdef MS_WINDOWS + /* On Windows, overallocate by 50% is the best factor */ +# define OVERALLOCATE_FACTOR 2 +#else + /* On Linux, overallocate by 25% is the best factor */ +# define OVERALLOCATE_FACTOR 4 +#endif Py_ssize_t newlen; PyObject *newbuffer; @@ -13107,9 +13114,10 @@ int if (writer->buffer == NULL) { assert(!writer->readonly); - if (writer->overallocate && newlen <= (PY_SSIZE_T_MAX - newlen / 4)) { - /* overallocate 25% to limit the number of resize */ - newlen += newlen / 4; + if (writer->overallocate + && newlen <= (PY_SSIZE_T_MAX - newlen / OVERALLOCATE_FACTOR)) { + /* overallocate to limit the number of realloc() */ + newlen += newlen / OVERALLOCATE_FACTOR; } if (newlen < writer->min_length) newlen = writer->min_length; @@ -13119,9 +13127,10 @@ int return -1; } else if (newlen > writer->size) { - if (writer->overallocate && newlen <= (PY_SSIZE_T_MAX - newlen / 4)) { - /* overallocate 25% to limit the number of resize */ - newlen += newlen / 4; + if (writer->overallocate + && newlen <= (PY_SSIZE_T_MAX - newlen / OVERALLOCATE_FACTOR)) { + /* overallocate to limit the number of realloc() */ + newlen += newlen / OVERALLOCATE_FACTOR; } if (newlen < writer->min_length) newlen = writer->min_length; @@ -13155,6 +13164,8 @@ int } _PyUnicodeWriter_Update(writer); return 0; + +#undef OVERALLOCATE_FACTOR } Py_LOCAL_INLINE(int)