From 616ee6448930fc69aa29f0220e7c87978846a69a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 13 May 2025 15:31:41 +0200 Subject: [PATCH] gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (GH-133969) Don't call PyObject_Str() if the input type is str. (cherry picked from commit fe9f6e829a535747b1e06d9bfda033a9a47165ed) Co-authored-by: Victor Stinner --- Objects/unicodeobject.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4e1aafb91fc8f1..9b8e3bb5462d4b 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -13954,7 +13954,12 @@ _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str) int PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj) { - if (Py_TYPE(obj) == &PyLong_Type) { + PyTypeObject *type = Py_TYPE(obj); + if (type == &PyUnicode_Type) { + return _PyUnicodeWriter_WriteStr((_PyUnicodeWriter*)writer, obj); + } + + if (type == &PyLong_Type) { return _PyLong_FormatWriter((_PyUnicodeWriter*)writer, obj, 10, 0); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy