@@ -5293,42 +5293,53 @@ get_base_by_token_recursive(PyTypeObject *type, void *token)
5293
5293
}
5294
5294
5295
5295
static inline int
5296
- _token_found (PyTypeObject * type , PyTypeObject * * result )
5296
+ _token_found (PyTypeObject * * result , PyTypeObject * type )
5297
5297
{
5298
5298
if (result != NULL ) {
5299
5299
* result = (PyTypeObject * )Py_NewRef (type );
5300
5300
}
5301
5301
return 1 ;
5302
5302
}
5303
5303
5304
+ // Prefer this to gotos for optimization
5305
+ static inline int
5306
+ _token_not_found (PyTypeObject * * result , int ret )
5307
+ {
5308
+ assert (-1 <= ret && ret <= 0 );
5309
+ if (result != NULL ) {
5310
+ * result = NULL ;
5311
+ }
5312
+ return ret ;
5313
+ }
5314
+
5304
5315
int
5305
5316
PyType_GetBaseByToken (PyTypeObject * type , void * token , PyTypeObject * * result )
5306
5317
{
5307
5318
if (token == NULL ) {
5308
5319
PyErr_Format (PyExc_SystemError ,
5309
5320
"PyType_GetBaseByToken called with token=NULL" );
5310
- goto error ;
5321
+ return _token_not_found ( result , -1 ) ;
5311
5322
}
5312
5323
if (!PyType_Check (type )) {
5313
5324
PyErr_Format (PyExc_TypeError ,
5314
5325
"expected a type, got a '%T' object" , type );
5315
- goto error ;
5326
+ return _token_not_found ( result , -1 ) ;
5316
5327
}
5317
5328
if (!_PyType_HasFeature (type , Py_TPFLAGS_HEAPTYPE )) {
5318
5329
// Static type MRO contains no heap type,
5319
5330
// which type_ready_mro() ensures.
5320
- goto not_found ;
5331
+ return _token_not_found ( result , 0 ) ;
5321
5332
}
5322
5333
if (((PyHeapTypeObject * )type )-> ht_token == token ) {
5323
- return _token_found (type , result );
5334
+ return _token_found (result , type );
5324
5335
}
5325
5336
PyObject * mro = type -> tp_mro ;
5326
5337
if (mro == NULL ) {
5327
5338
PyTypeObject * base = get_base_by_token_recursive (type , token );
5328
5339
if (base != NULL ) {
5329
- return _token_found (base , result );
5340
+ return _token_found (result , base );
5330
5341
}
5331
- goto not_found ;
5342
+ return _token_not_found ( result , 0 ) ;
5332
5343
}
5333
5344
assert (PyTuple_Check (mro ));
5334
5345
// mro_invoke() ensures that the type MRO cannot be empty.
@@ -5343,19 +5354,10 @@ PyType_GetBaseByToken(PyTypeObject *type, void *token, PyTypeObject **result)
5343
5354
continue ;
5344
5355
}
5345
5356
if (((PyHeapTypeObject * )base )-> ht_token == token ) {
5346
- return _token_found (base , result );
5357
+ return _token_found (result , base );
5347
5358
}
5348
5359
}
5349
- not_found :
5350
- if (result != NULL ) {
5351
- * result = NULL ;
5352
- }
5353
- return 0 ;
5354
- error :
5355
- if (result != NULL ) {
5356
- * result = NULL ;
5357
- }
5358
- return -1 ;
5360
+ return _token_not_found (result , 0 );
5359
5361
}
5360
5362
5361
5363
0 commit comments