diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-10-09 20:43:24 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-10-09 20:43:24 (GMT) |
commit | be75b8cf2310e0be0f32590a1c0df919058002e8 (patch) | |
tree | d722afaec725263f1bf050dd99040de7929d4d61 /Include | |
parent | aecf63ee3a4408e9a6186b08d924d1492234dbea (diff) | |
download | cpython-be75b8cf2310e0be0f32590a1c0df919058002e8.zip cpython-be75b8cf2310e0be0f32590a1c0df919058002e8.tar.gz cpython-be75b8cf2310e0be0f32590a1c0df919058002e8.tar.bz2 |
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.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/longobject.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Include/longobject.h b/Include/longobject.h index aed59ce..ab92495 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -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( |