mirror of
https://github.com/python/cpython.git
synced 2025-12-10 02:50:09 +00:00
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:
parent
aecf63ee3a
commit
be75b8cf23
3 changed files with 136 additions and 27 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue