Mercurial > cpython-lru_cache-weakref
diff Python/sysmodule.c @ 86964:a2f42d57b91d
Issue #19512: sys_displayhook() now uses an identifier for "builtins"
dictionary key and only decodes "\n" string once to write a newline.
So "builtins" and "\n" are only decoded once from UTF-8, at the first call.
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Wed, 06 Nov 2013 18:27:13 +0100 |
| parents | 4ef4578db38a |
| children | 5e402c16a74c |
line wrap: on
line diff
--- a/Python/sysmodule.c Wed Nov 06 17:25:17 2013 +0100 +++ b/Python/sysmodule.c Wed Nov 06 18:27:13 2013 +0100 @@ -137,10 +137,13 @@ PyObject *outf; PyInterpreterState *interp = PyThreadState_GET()->interp; PyObject *modules = interp->modules; - PyObject *builtins = PyDict_GetItemString(modules, "builtins"); + PyObject *builtins; + static PyObject *newline = NULL; int err; _Py_IDENTIFIER(_); + _Py_IDENTIFIER(builtins); + builtins = _PyDict_GetItemId(modules, &PyId_builtins); if (builtins == NULL) { PyErr_SetString(PyExc_RuntimeError, "lost builtins module"); return NULL; @@ -173,7 +176,12 @@ return NULL; } } - if (PyFile_WriteString("\n", outf) != 0) + if (newline == NULL) { + newline = PyUnicode_FromString("\n"); + if (newline == NULL) + return NULL; + } + if (PyFile_WriteObject(newline, outf, Py_PRINT_RAW) != 0) return NULL; if (_PyObject_SetAttrId(builtins, &PyId__, o) != 0) return NULL;
