summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-11-18 20:08:39 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-11-18 20:08:39 (GMT)
commit6989ba01742a556ebc790b4786ba1d4f4ef78692 (patch)
tree6347c168555b98676ad2ef47b2dcaa57eebd7cac
parentf47981f51e5c825b71652ba05a982e7a437c9bce (diff)
downloadcpython-6989ba01742a556ebc790b4786ba1d4f4ef78692.zip
cpython-6989ba01742a556ebc790b4786ba1d4f4ef78692.tar.gz
cpython-6989ba01742a556ebc790b4786ba1d4f4ef78692.tar.bz2
Issue #19581: Change the overallocation factor of _PyUnicodeWriter on Windows
On Windows, a factor of 50% gives best performances.
-rw-r--r--Objects/unicodeobject.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index b2f488d..bddfafd 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -13106,6 +13106,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;
@@ -13121,9 +13128,10 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
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;
@@ -13133,9 +13141,10 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
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;
@@ -13169,6 +13178,8 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
}
_PyUnicodeWriter_Update(writer);
return 0;
+
+#undef OVERALLOCATE_FACTOR
}
Py_LOCAL_INLINE(int)