Issue #25349: Optimize bytes % int

Optimize bytes.__mod__(args) for integere formats: %d (%i, %u), %o, %x and %X.
_PyBytesWriter is now used to format directly the integer into the writer
buffer, instead of using a temporary bytes object.

Formatting is between 30% and 50% faster on a microbenchmark.
This commit is contained in:
Victor Stinner 2015-10-09 22:43:24 +02:00
parent aecf63ee3a
commit be75b8cf23
3 changed files with 136 additions and 27 deletions

View file

@ -182,6 +182,13 @@ PyAPI_FUNC(int) _PyLong_FormatWriter(
int base,
int alternate);
PyAPI_FUNC(char*) _PyLong_FormatBytesWriter(
_PyBytesWriter *writer,
char *str,
PyObject *obj,
int base,
int alternate);
/* Format the object based on the format_spec, as defined in PEP 3101
(Advanced String Formatting). */
PyAPI_FUNC(int) _PyLong_FormatAdvancedWriter(