diff options
author | Mark Shannon <mark@hotpy.org> | 2023-03-13 10:34:54 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 10:34:54 +0000 |
commit | 233e32f93614255bf5fc7c93cd98af453e58cc98 (patch) | |
tree | 9eb812f9894064fb34f5e2ee14a019ec4a58da32 /Python/ceval_macros.h | |
parent | 78e4e6c3d71980d4e6687f07afa6ddfc83e29b04 (diff) | |
download | cpython-233e32f93614255bf5fc7c93cd98af453e58cc98.tar.gz cpython-233e32f93614255bf5fc7c93cd98af453e58cc98.zip |
GH-102300: Reuse objects with refcount == 1 in float specialized binary ops. (GH-102301)
Diffstat (limited to 'Python/ceval_macros.h')
-rw-r--r-- | Python/ceval_macros.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index ac1fec77dac..98b72ec1b36 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -350,3 +350,23 @@ GETITEM(PyObject *v, Py_ssize_t i) { #define KWNAMES_LEN() \ (kwnames == NULL ? 0 : ((int)PyTuple_GET_SIZE(kwnames))) + +#define DECREF_INPUTS_AND_REUSE_FLOAT(left, right, dval, result) \ +do { \ + if (Py_REFCNT(left) == 1) { \ + ((PyFloatObject *)left)->ob_fval = (dval); \ + _Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);\ + result = (left); \ + } \ + else if (Py_REFCNT(right) == 1) {\ + ((PyFloatObject *)right)->ob_fval = (dval); \ + _Py_DECREF_NO_DEALLOC(left); \ + result = (right); \ + }\ + else { \ + result = PyFloat_FromDouble(dval); \ + if ((result) == NULL) goto error; \ + _Py_DECREF_NO_DEALLOC(left); \ + _Py_DECREF_NO_DEALLOC(right); \ + } \ +} while (0) |