From 3286964fea140340e75c7e25cd394f372902d517 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Tue, 22 Feb 2022 11:23:42 -0500 Subject: [PATCH] Optimize error_string creation --- include/pybind11/detail/type_caster_base.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index abd0c67b9..1ed23fb91 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -502,9 +502,13 @@ error_string(PyObject *exc_type, PyObject *exc_value, PyObject *exc_trace) { Py_INCREF(f_code); # endif int lineno = PyFrame_GetLineNumber(frame); - result += std::string(" ") + handle(f_code->co_filename).cast() + '(' - + std::to_string(lineno) - + "): " + handle(f_code->co_name).cast() + '\n'; + result += " "; + result += handle(f_code->co_filename).cast(); + result += '('; + result += std::to_string(lineno); + result += "):) "; + result += handle(f_code->co_name).cast(); + result += '\n'; frame = frame->f_back; Py_DECREF(f_code); }