Visitar URL original
GH-93516: Speedup line number checks when tracing. by markshannon · Pull Request #93763 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into speedup-line-checks-v3
  • Loading branch information
markshannon committed Jun 13, 2022
commit 47cb2edf0d472fd42e54666f47f74d23f61523d7
17 changes: 13 additions & 4 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,10 @@ _PyCode_CreateLineArray(PyCodeObject *co)
if (!_PyLineTable_NextAddressRange(&bounds)) {
break;
}
int index = bounds.ar_start;
while (index < bounds.ar_end && index < Py_SIZE(co)) {
int addr = bounds.ar_start;
while (addr < bounds.ar_end) {
assert(addr < (int)(Py_SIZE(co) * sizeof(_Py_CODEUNIT)));
int index = addr / sizeof(_Py_CODEUNIT);
if (size == 2) {
assert(((int16_t)bounds.ar_line) == bounds.ar_line);
((int16_t *)co->_co_linearray)[index] = bounds.ar_line;
Expand All @@ -741,7 +743,7 @@ _PyCode_CreateLineArray(PyCodeObject *co)
assert(size == 4);
((int32_t *)co->_co_linearray)[index] = bounds.ar_line;
}
index++;
addr += sizeof(_Py_CODEUNIT);
}
}
return 0;
Expand All @@ -753,10 +755,10 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
if (addrq < 0) {
return co->co_firstlineno;
}
assert(addrq >= 0 && addrq < _PyCode_NBYTES(co));
if (co->_co_linearray) {
return _PyCode_LineNumberFromArray(co, addrq / sizeof(_Py_CODEUNIT));
}
assert(addrq >= 0 && addrq < _PyCode_NBYTES(co));
PyCodeAddressRange bounds;
_PyCode_InitAddressRange(co, &bounds);
return _PyCode_CheckLineNumber(addrq, &bounds);
Expand Down Expand Up @@ -1596,6 +1598,9 @@ code_dealloc(PyCodeObject *co)
if (co->co_weakreflist != NULL) {
PyObject_ClearWeakRefs((PyObject*)co);
}
if (co->_co_linearray) {
PyMem_Free(co->_co_linearray);
}
if (co->co_warmup == 0) {
_Py_QuickenedCount--;
}
Expand Down Expand Up @@ -2153,6 +2158,10 @@ _PyStaticCode_Dealloc(PyCodeObject *co)
PyObject_ClearWeakRefs((PyObject *)co);
co->co_weakreflist = NULL;
}
if (co->_co_linearray) {
PyMem_Free(co->_co_linearray);
co->_co_linearray = NULL;
}
}

int
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.