mirror of
https://github.com/python/cpython.git
synced 2025-08-28 20:56:54 +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
|
@ -6499,7 +6499,7 @@ _PyUnicode_AsASCIIString(PyObject *unicode, const char *errors)
|
|||
return NULL;
|
||||
/* Fast path: if it is an ASCII-only string, construct bytes object
|
||||
directly. Else defer to above function to raise the exception. */
|
||||
if (PyUnicode_MAX_CHAR_VALUE(unicode) < 128)
|
||||
if (PyUnicode_IS_ASCII(unicode))
|
||||
return PyBytes_FromStringAndSize(PyUnicode_DATA(unicode),
|
||||
PyUnicode_GET_LENGTH(unicode));
|
||||
return unicode_encode_ucs1(unicode, errors, 128);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue