Commit b330b685 authored by Stefan Behnel's avatar Stefan Behnel

Call ".tp_repr()" instead of ".tp_str()" when formatting builtin types, since...

Call ".tp_repr()" instead of ".tp_str()" when formatting builtin types, since it avoids an indirection in Py3.8.
......@@ -1100,11 +1100,12 @@ static PyObject* __Pyx_PyObject_Format(PyObject* obj, PyObject* format_spec) {
likely(PyString_CheckExact(s)) ? PyUnicode_FromEncodedObject(s, NULL, "strict") : \
PyObject_Format(s, f))
#elif CYTHON_USE_TYPE_SLOTS
// Py3 nicely returns unicode strings from str() which makes this quite efficient for builtin types
// Py3 nicely returns unicode strings from str() and repr(), which makes this quite efficient for builtin types.
// In Py3.8+, tp_str() delegates to tp_repr(), so we call tp_repr() directly here.
#define __Pyx_PyObject_FormatSimple(s, f) ( \
likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) : \
likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_str(s) : \
likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_str(s) : \
likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_repr(s) : \
likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_repr(s) : \
PyObject_Format(s, f))
#else
#define __Pyx_PyObject_FormatSimple(s, f) ( \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment