mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-130704: Strength reduce LOAD_FAST{_LOAD_FAST}
(#130708)
Optimize `LOAD_FAST` opcodes into faster versions that load borrowed references onto the operand stack when we can prove that the lifetime of the local outlives the lifetime of the temporary that is loaded onto the stack.
This commit is contained in:
parent
e9556e1004
commit
053c285f6b
35 changed files with 1282 additions and 345 deletions
|
@ -135,8 +135,6 @@ PyFloat_FromDouble(double fval)
|
|||
return (PyObject *) op;
|
||||
}
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
|
||||
_PyStackRef _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef right, double value)
|
||||
{
|
||||
PyStackRef_CLOSE_SPECIALIZED(left, _PyFloat_ExactDealloc);
|
||||
|
@ -144,35 +142,6 @@ _PyStackRef _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef righ
|
|||
return PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(value));
|
||||
}
|
||||
|
||||
#else // Py_GIL_DISABLED
|
||||
|
||||
_PyStackRef _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef right, double value)
|
||||
{
|
||||
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
|
||||
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
|
||||
if (Py_REFCNT(left_o) == 1) {
|
||||
((PyFloatObject *)left_o)->ob_fval = value;
|
||||
PyStackRef_CLOSE_SPECIALIZED(right, _PyFloat_ExactDealloc);
|
||||
return left;
|
||||
}
|
||||
else if (Py_REFCNT(right_o) == 1) {
|
||||
((PyFloatObject *)right_o)->ob_fval = value;
|
||||
PyStackRef_CLOSE_SPECIALIZED(left, _PyFloat_ExactDealloc);
|
||||
return right;
|
||||
}
|
||||
else {
|
||||
PyObject *result = PyFloat_FromDouble(value);
|
||||
PyStackRef_CLOSE_SPECIALIZED(left, _PyFloat_ExactDealloc);
|
||||
PyStackRef_CLOSE_SPECIALIZED(right, _PyFloat_ExactDealloc);
|
||||
if (result == NULL) {
|
||||
return PyStackRef_NULL;
|
||||
}
|
||||
return PyStackRef_FromPyObjectStealMortal(result);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Py_GIL_DISABLED
|
||||
|
||||
static PyObject *
|
||||
float_from_string_inner(const char *s, Py_ssize_t len, void *obj)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue