cpython: Issue #23910: Optimize property() getter calls. Patch by Joe Jevnik
https://hg.python.org/cpython/rev/661cdbd617b8 changeset: 95830:661cdbd617b8 user: Raymond Hettinger <python@rcn.com> date: Thu Apr 30 08:08:13 2015 -0700 summary: Issue #23910: Optimize property() getter calls. Patch by Joe Jevnik files: Misc/NEWS | 2 ++ Objects/descrobject.c | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,8 @@ - Issue #23996: Avoid a crash when a delegated generator raises an unnormalized StopIteration exception. Patch by Stefan Behnel. +- Issue #23910: Optimize property() getter calls. Patch by Joe Jevnik. + - Issue #24022: Fix tokenizer crash when processing undecodable source code. - Issue #9951: Added a hex() method to bytes, bytearray, and memoryview. diff --git a/Objects/descrobject.c b/Objects/descrobject.c --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1372,6 +1372,8 @@ static PyObject * property_descr_get(PyObject *self, PyObject *obj, PyObject *type) { + static PyObject *args = NULL; + PyObject *ret; propertyobject *gs = (propertyobject *)self; if (obj == NULL || obj == Py_None) { @@ -1382,7 +1384,13 @@ PyErr_SetString(PyExc_AttributeError, "unreadable attribute"); return NULL; } - return PyObject_CallFunctionObjArgs(gs->prop_get, obj, NULL); + if (!args && !(args = PyTuple_New(1))) { + return NULL; + } + PyTuple_SET_ITEM(args, 0, obj); + ret = PyObject_Call(gs->prop_get, args, NULL); + PyTuple_SET_ITEM(args, 0, NULL); + return ret; } static int -- Repository URL: https://hg.python.org/cpython
participants (1)
-
raymond.hettinger