]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-119396: Optimize PyUnicode_FromFormat() UTF-8 decoder (#119398)
authorVictor Stinner <vstinner@python.org>
Wed, 22 May 2024 21:05:26 +0000 (23:05 +0200)
committerGitHub <noreply@github.com>
Wed, 22 May 2024 21:05:26 +0000 (21:05 +0000)
commit9b422fc6af87b81812aaf3010c004eb27c4dc280
tree306e72e7ff377b61477790ac8c9efd38b5f3445b
parent14b063cbf1bb11a489d04a31f277edba0fc8893c
gh-119396: Optimize PyUnicode_FromFormat() UTF-8 decoder (#119398)

Add unicode_decode_utf8_writer() to write directly characters into a
_PyUnicodeWriter writer: avoid the creation of a temporary string.
Optimize PyUnicode_FromFormat() by using the new
unicode_decode_utf8_writer().

Rename unicode_fromformat_write_cstr() to
unicode_fromformat_write_utf8().

Microbenchmark on the code:

    return PyUnicode_FromFormat(
        "%s %s %s %s %s.",
        "format", "multiple", "utf8", "short", "strings");

Result: 620 ns +- 8 ns -> 382 ns +- 2 ns: 1.62x faster.
Objects/unicodeobject.c