GH-127953: Make line number lookup O(1) regardless of the size of the code object (GH-128350)

This commit is contained in:
Mark Shannon 2025-01-21 09:33:23 +00:00 committed by GitHub
parent f7cc7d296c
commit 7239da7559
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 214 additions and 163 deletions

View file

@ -979,6 +979,9 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
if (addrq < 0) {
return co->co_firstlineno;
}
if (co->_co_monitoring && co->_co_monitoring->lines) {
return _Py_Instrumentation_GetLine(co, addrq/sizeof(_Py_CODEUNIT));
}
assert(addrq >= 0 && addrq < _PyCode_NBYTES(co));
PyCodeAddressRange bounds;
_PyCode_InitAddressRange(co, &bounds);