mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
gh-93382: Cache result of PyCode_GetCode in codeobject (GH-93383)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
This commit is contained in:
parent
d8f40ead92
commit
d52ffc1d1f
5 changed files with 21 additions and 4 deletions
|
|
@ -458,22 +458,30 @@ _PyFrame_GetState(PyFrameObject *frame)
|
|||
static void
|
||||
add_load_fast_null_checks(PyCodeObject *co)
|
||||
{
|
||||
int changed = 0;
|
||||
_Py_CODEUNIT *instructions = _PyCode_CODE(co);
|
||||
for (Py_ssize_t i = 0; i < Py_SIZE(co); i++) {
|
||||
switch (_Py_OPCODE(instructions[i])) {
|
||||
case LOAD_FAST:
|
||||
case LOAD_FAST__LOAD_FAST:
|
||||
case LOAD_FAST__LOAD_CONST:
|
||||
changed = 1;
|
||||
_Py_SET_OPCODE(instructions[i], LOAD_FAST_CHECK);
|
||||
break;
|
||||
case LOAD_CONST__LOAD_FAST:
|
||||
changed = 1;
|
||||
_Py_SET_OPCODE(instructions[i], LOAD_CONST);
|
||||
break;
|
||||
case STORE_FAST__LOAD_FAST:
|
||||
changed = 1;
|
||||
_Py_SET_OPCODE(instructions[i], STORE_FAST);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
// invalidate cached co_code object
|
||||
Py_CLEAR(co->_co_code);
|
||||
}
|
||||
}
|
||||
|
||||
/* Setter for f_lineno - you can set f_lineno from within a trace function in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue