mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Optimize ascii(str): don't encode/decode repr if repr is already ASCII
This commit is contained in:
parent
322cc7438c
commit
af03757d20
2 changed files with 4 additions and 1 deletions
|
|
@ -451,6 +451,9 @@ PyObject_ASCII(PyObject *v)
|
|||
if (repr == NULL)
|
||||
return NULL;
|
||||
|
||||
if (PyUnicode_IS_ASCII(repr))
|
||||
return repr;
|
||||
|
||||
/* repr is guaranteed to be a PyUnicode object by PyObject_Repr */
|
||||
ascii = _PyUnicode_AsASCIIString(repr, "backslashreplace");
|
||||
Py_DECREF(repr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue