From e3c7381c39f02a29538ba0dc2f5731aee73ceb1a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 7 May 2010 00:41:18 +0000 Subject: [PATCH] code_repr(): use %U to format the filename Avoid useless unicode decoding/recoding of the filename. --- Objects/codeobject.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 3e71e4cde3d..ad2068bb2a8 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -340,16 +340,20 @@ code_dealloc(PyCodeObject *co) static PyObject * code_repr(PyCodeObject *co) { - int lineno = -1; - char *filename = "???"; - + int lineno; if (co->co_firstlineno != 0) lineno = co->co_firstlineno; - if (co->co_filename && PyUnicode_Check(co->co_filename)) - filename = _PyUnicode_AsString(co->co_filename); - return PyUnicode_FromFormat( - "", - co->co_name, co, filename, lineno); + else + lineno = -1; + if (co->co_filename && PyUnicode_Check(co->co_filename)) { + return PyUnicode_FromFormat( + "", + co->co_name, co, co->co_filename, lineno); + } else { + return PyUnicode_FromFormat( + "", + co->co_name, co, lineno); + } } static PyObject *