[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

@ -804,8 +804,10 @@ resume_frame:
int original_opcode = 0;
if (tstate->tracing) {
PyCodeObject *code = _PyFrame_GetCode(frame);
original_opcode = code->_co_monitoring->lines[(int)(here - _PyCode_CODE(code))].original_opcode;
} else {
int index = (int)(here - _PyCode_CODE(code));
original_opcode = code->_co_monitoring->lines->data[index*code->_co_monitoring->lines->bytes_per_entry];
}
else {
_PyFrame_SetStackPointer(frame, stack_pointer);
original_opcode = _Py_call_instrumentation_line(
tstate, frame, here, prev);