[3.11] GH-93516: Backport GH-93769: Speedup line number checks when tracing (GH-94127)

Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
This commit is contained in:
Mark Shannon 2022-06-22 16:32:02 +01:00 committed by GitHub
parent 8c2af49071
commit 3ece6e6feb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 409 additions and 298 deletions

View file

@ -475,6 +475,35 @@ write_location_entry_start(uint8_t *ptr, int code, int length)
}
/* Line array cache for tracing */
extern int _PyCode_CreateLineArray(PyCodeObject *co);
static inline int
_PyCode_InitLineArray(PyCodeObject *co)
{
if (co->_co_linearray) {
return 0;
}
return _PyCode_CreateLineArray(co);
}
static inline int
_PyCode_LineNumberFromArray(PyCodeObject *co, int index)
{
assert(co->_co_linearray != NULL);
assert(index >= 0);
assert(index < Py_SIZE(co));
if (co->_co_linearray_entry_size == 2) {
return ((int16_t *)co->_co_linearray)[index];
}
else {
assert(co->_co_linearray_entry_size == 4);
return ((int32_t *)co->_co_linearray)[index];
}
}
#ifdef __cplusplus
}
#endif