mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-107674: Lazy load line number to improve performance of tracing (GH-118127)
This commit is contained in:
parent
c7e7bfc4ca
commit
375c94c75d
4 changed files with 61 additions and 19 deletions
|
@ -41,12 +41,20 @@ int
|
|||
PyFrame_GetLineNumber(PyFrameObject *f)
|
||||
{
|
||||
assert(f != NULL);
|
||||
if (f->f_lineno != 0) {
|
||||
if (f->f_lineno == -1) {
|
||||
// We should calculate it once. If we can't get the line number,
|
||||
// set f->f_lineno to 0.
|
||||
f->f_lineno = PyUnstable_InterpreterFrame_GetLine(f->f_frame);
|
||||
if (f->f_lineno < 0) {
|
||||
f->f_lineno = 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (f->f_lineno > 0) {
|
||||
return f->f_lineno;
|
||||
}
|
||||
else {
|
||||
return PyUnstable_InterpreterFrame_GetLine(f->f_frame);
|
||||
}
|
||||
return PyUnstable_InterpreterFrame_GetLine(f->f_frame);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue