diff options
author | Mark Shannon <mark@hotpy.org> | 2021-06-04 00:03:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-04 00:03:54 (GMT) |
commit | b2bf2bc1ece673d387341e06c8d3c2bc6e259747 (patch) | |
tree | 29217a2927ed27e71e6324876f279946219a25a9 /Objects | |
parent | 35002aa8f62dda1f79035e9904abdf476683e9be (diff) | |
download | cpython-b2bf2bc1ece673d387341e06c8d3c2bc6e259747.zip cpython-b2bf2bc1ece673d387341e06c8d3c2bc6e259747.tar.gz cpython-b2bf2bc1ece673d387341e06c8d3c2bc6e259747.tar.bz2 |
bpo-43693: Compute deref offsets in compiler (gh-25152)
Merges locals and cells into a single array.
Saves a pointer in the interpreter and means that we don't need the LOAD_CLOSURE opcode any more
https://bugs.python.org/issue43693
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/clinic/codeobject.c.h | 22 | ||||
-rw-r--r-- | Objects/codeobject.c | 9 |
2 files changed, 8 insertions, 23 deletions
diff --git a/Objects/clinic/codeobject.c.h b/Objects/clinic/codeobject.c.h index 629d265..c1ad09c 100644 --- a/Objects/clinic/codeobject.c.h +++ b/Objects/clinic/codeobject.c.h @@ -375,7 +375,7 @@ exit: } PyDoc_STRVAR(code__varname_from_oparg__doc__, -"_varname_from_oparg($self, /, oparg, *, cell=False)\n" +"_varname_from_oparg($self, /, oparg)\n" "--\n" "\n" "(internal-only) Return the local variable name for the given oparg.\n" @@ -386,18 +386,16 @@ PyDoc_STRVAR(code__varname_from_oparg__doc__, {"_varname_from_oparg", (PyCFunction)(void(*)(void))code__varname_from_oparg, METH_FASTCALL|METH_KEYWORDS, code__varname_from_oparg__doc__}, static PyObject * -code__varname_from_oparg_impl(PyCodeObject *self, int oparg, int cell); +code__varname_from_oparg_impl(PyCodeObject *self, int oparg); static PyObject * code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; - static const char * const _keywords[] = {"oparg", "cell", NULL}; + static const char * const _keywords[] = {"oparg", NULL}; static _PyArg_Parser _parser = {NULL, _keywords, "_varname_from_oparg", 0}; - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; + PyObject *argsbuf[1]; int oparg; - int cell = 0; args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); if (!args) { @@ -407,17 +405,9 @@ code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t n if (oparg == -1 && PyErr_Occurred()) { goto exit; } - if (!noptargs) { - goto skip_optional_kwonly; - } - cell = PyObject_IsTrue(args[1]); - if (cell < 0) { - goto exit; - } -skip_optional_kwonly: - return_value = code__varname_from_oparg_impl(self, oparg, cell); + return_value = code__varname_from_oparg_impl(self, oparg); exit: return return_value; } -/*[clinic end generated code: output=43f4eef80d584fe0 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ba4c5487e0364ce8 input=a9049054013a1b77]*/ diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 051aefe..b82a1b5 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -1547,8 +1547,6 @@ error: code._varname_from_oparg oparg: int - * - cell: bool = False (internal-only) Return the local variable name for the given oparg. @@ -1556,12 +1554,9 @@ WARNING: this method is for internal use only and may change or go away. [clinic start generated code]*/ static PyObject * -code__varname_from_oparg_impl(PyCodeObject *self, int oparg, int cell) -/*[clinic end generated code: output=c7d39c9723692c8f input=2945bb291d3a3118]*/ +code__varname_from_oparg_impl(PyCodeObject *self, int oparg) +/*[clinic end generated code: output=1fd1130413184206 input=c5fa3ee9bac7d4ca]*/ { - if (cell) { - oparg += self->co_nlocals; - } PyObject *name = PyTuple_GetItem(self->co_localsplusnames, oparg); if (name == NULL) { return NULL; |