]> granicus.if.org Git - python/commitdiff
Issue #23910: Optimize property() getter calls. Patch by Joe Jevnik
authorRaymond Hettinger <python@rcn.com>
Thu, 30 Apr 2015 15:08:13 +0000 (08:08 -0700)
committerRaymond Hettinger <python@rcn.com>
Thu, 30 Apr 2015 15:08:13 +0000 (08:08 -0700)
Misc/NEWS
Objects/descrobject.c

index 6baf57ceed5a7124981a5a23c971c4a356dfcdc5..fad05027447cc526a24b6168ca2f871e10dcabb9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,8 @@ Core and Builtins
 - 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.
index 2df5ac5f731bd63fd42d31102f2a2d76c3c72c90..822fb4182b2765b22b64e3ff8b8d8a74cf565a5c 100644 (file)
@@ -1372,6 +1372,8 @@ property_dealloc(PyObject *self)
 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 @@ property_descr_get(PyObject *self, PyObject *obj, PyObject *type)
         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