mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
GH-125837: Split LOAD_CONST
into three. (GH-125972)
* Add LOAD_CONST_IMMORTAL opcode * Add LOAD_SMALL_INT opcode * Remove RETURN_CONST opcode
This commit is contained in:
parent
67f5c5bd6f
commit
faa3272fb8
33 changed files with 706 additions and 538 deletions
|
@ -442,11 +442,13 @@ _PyCode_Quicken(PyCodeObject *code)
|
|||
{
|
||||
#if ENABLE_SPECIALIZATION
|
||||
int opcode = 0;
|
||||
int oparg = 0;
|
||||
_Py_CODEUNIT *instructions = _PyCode_CODE(code);
|
||||
/* The last code unit cannot have a cache, so we don't need to check it */
|
||||
for (int i = 0; i < Py_SIZE(code)-1; i++) {
|
||||
opcode = instructions[i].op.code;
|
||||
int caches = _PyOpcode_Caches[opcode];
|
||||
oparg = (oparg << 8) | instructions[i].op.arg;
|
||||
if (caches) {
|
||||
// The initial value depends on the opcode
|
||||
switch (opcode) {
|
||||
|
@ -465,6 +467,18 @@ _PyCode_Quicken(PyCodeObject *code)
|
|||
}
|
||||
i += caches;
|
||||
}
|
||||
else if (opcode == LOAD_CONST) {
|
||||
/* We can't do this in the bytecode compiler as
|
||||
* marshalling can intern strings and make them immortal. */
|
||||
|
||||
PyObject *obj = PyTuple_GET_ITEM(code->co_consts, oparg);
|
||||
if (_Py_IsImmortal(obj)) {
|
||||
instructions[i].op.code = LOAD_CONST_IMMORTAL;
|
||||
}
|
||||
}
|
||||
if (opcode != EXTENDED_ARG) {
|
||||
oparg = 0;
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_SPECIALIZATION */
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue