Commit e4c7e9f2 authored by Stefan Behnel's avatar Stefan Behnel

avoid formatting call overhead for simple Unicode value case

parent ccd84b10
......@@ -3024,8 +3024,15 @@ class FormattedValueNode(ExprNode):
))
code.put_gotref(conversion_result)
code.put("%s = PyObject_Format(%s, %s); " % (
if isinstance(self.format_spec, UnicodeNode) and not self.format_spec.value:
# common case: no format spec => expect Unicode pass-through
format_func = '__Pyx_PyObject_FormatSimple'
else:
format_func = 'PyObject_Format'
code.put("%s = %s(%s, %s); " % (
self.result(),
format_func,
conversion_result,
self.format_spec.py_result()))
......
......@@ -123,6 +123,7 @@
#define PyObject_Realloc(p) PyMem_Realloc(p)
#endif
#define __Pyx_PyObject_FormatSimple(s, f) (likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) : PyObject_Format(s, f))
#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
......
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