[3.13] GH-127953: Make line number lookup O(1) regardless of the size of the code object (#129127)

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-04-07 19:15:02 +01:00 committed by GitHub
parent 1fcf409ace
commit 3f3863281b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 208 additions and 156 deletions

View file

@ -987,6 +987,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);