@@ -59,7 +59,7 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
5959 /* the dict is created on the fly in PyObject_GenericSetAttr */
6060 self -> dict = NULL ;
6161 self -> notes = NULL ;
62- PyTime_TimeRaw ( & self -> timestamp_ns ); /* fills in 0 on failure. */
62+ self -> timestamp_ns = 0 ;
6363 self -> traceback = self -> cause = self -> context = NULL ;
6464 self -> suppress_context = 0 ;
6565
@@ -84,7 +84,12 @@ BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
8484 return -1 ;
8585
8686 Py_XSETREF (self -> args , Py_NewRef (args ));
87- PyTime_TimeRaw (& self -> timestamp_ns ); /* fills in 0 on failure. */
87+ if (Py_IS_TYPE (self , (PyTypeObject * )PyExc_StopIteration ) ||
88+ Py_IS_TYPE (self , (PyTypeObject * )PyExc_StopAsyncIteration )) {
89+ self -> timestamp_ns = 0 ; /* fast; frequent non-error control flow. */
90+ } else {
91+ PyTime_TimeRaw (& self -> timestamp_ns ); /* fills in 0 on failure. */
92+ }
8893 return 0 ;
8994}
9095
@@ -186,17 +191,11 @@ BaseException_repr(PyBaseExceptionObject *self)
186191 PyObject * res ;
187192 Py_BEGIN_CRITICAL_SECTION (self );
188193 const char * name = _PyType_Name (Py_TYPE (self ));
189- // TODO: check the env var at startup and control timestamp inclusion here.
190194 if (PyTuple_GET_SIZE (self -> args ) == 1 ) {
191- // res = PyUnicode_FromFormat("%s(%R) [@t=%lldns]", name,
192- // PyTuple_GET_ITEM(self->args, 0),
193- // self->timestamp_ns);
194195 res = PyUnicode_FromFormat ("%s(%R)" , name ,
195196 PyTuple_GET_ITEM (self -> args , 0 ));
196197 }
197198 else {
198- // res = PyUnicode_FromFormat("%s%R [@t=%lldns]", name, self->args,
199- // self->timestamp_ns);
200199 res = PyUnicode_FromFormat ("%s%R" , name , self -> args );
201200 }
202201 Py_END_CRITICAL_SECTION ();
0 commit comments