mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-93516: Speedup line number checks when tracing. (GH-93763)
* Use a lookup table to reduce overhead of getting line numbers during tracing.
This commit is contained in:
parent
45e62a2bc1
commit
ab0e601016
6 changed files with 101 additions and 8 deletions
|
@ -461,6 +461,35 @@ adaptive_counter_backoff(uint16_t counter) {
|
|||
}
|
||||
|
||||
|
||||
/* 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue