Optimize ascii(str): don't encode/decode repr if repr is already ASCII

This commit is contained in:
Victor Stinner 2013-04-14 18:44:10 +02:00
parent 322cc7438c
commit af03757d20
2 changed files with 4 additions and 1 deletions

View file

@ -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);