diff options
author | Raymond Hettinger <python@rcn.com> | 2003-10-12 19:09:37 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-10-12 19:09:37 (GMT) |
commit | 8ae468965700fd9900efc28bff8fa2015dae2bef (patch) | |
tree | 1f3545b2d2a3ad8b7d5692a7f84daa88d850b29c /Objects/classobject.c | |
parent | cb2da43db8943e9e7b1d900bce1d6416339d6f64 (diff) | |
download | cpython-8ae468965700fd9900efc28bff8fa2015dae2bef.zip cpython-8ae468965700fd9900efc28bff8fa2015dae2bef.tar.gz cpython-8ae468965700fd9900efc28bff8fa2015dae2bef.tar.bz2 |
Simplify and speedup uses of Py_BuildValue():
* Py_BuildValue("(OOO)",a,b,c) --> PyTuple_Pack(3,a,b,c)
* Py_BuildValue("()",a) --> PyTuple_New(0)
* Py_BuildValue("O", a) --> Py_INCREF(a)
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r-- | Objects/classobject.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index 0df249d..b0e1934 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -750,7 +750,7 @@ instance_getattr(register PyInstanceObject *inst, PyObject *name) if (!PyErr_ExceptionMatches(PyExc_AttributeError)) return NULL; PyErr_Clear(); - args = Py_BuildValue("(OO)", inst, name); + args = PyTuple_Pack(2, inst, name); if (args == NULL) return NULL; res = PyEval_CallObject(func, args); @@ -847,9 +847,9 @@ instance_setattr(PyInstanceObject *inst, PyObject *name, PyObject *v) if (func == NULL) return instance_setattr1(inst, name, v); if (v == NULL) - args = Py_BuildValue("(OO)", inst, name); + args = PyTuple_Pack(2, inst, name); else - args = Py_BuildValue("(OOO)", inst, name, v); + args = PyTuple_Pack(3, inst, name, v); if (args == NULL) return -1; res = PyEval_CallObject(func, args); @@ -1038,7 +1038,7 @@ instance_subscript(PyInstanceObject *inst, PyObject *key) func = instance_getattr(inst, getitemstr); if (func == NULL) return NULL; - arg = Py_BuildValue("(O)", key); + arg = PyTuple_Pack(1, key); if (arg == NULL) { Py_DECREF(func); return NULL; @@ -1069,9 +1069,9 @@ instance_ass_subscript(PyInstanceObject *inst, PyObject *key, PyObject *value) if (func == NULL) return -1; if (value == NULL) - arg = Py_BuildValue("(O)", key); + arg = PyTuple_Pack(1, key); else - arg = Py_BuildValue("(OO)", key, value); + arg = PyTuple_Pack(2, key, value); if (arg == NULL) { Py_DECREF(func); return -1; @@ -1281,7 +1281,7 @@ instance_contains(PyInstanceObject *inst, PyObject *member) if (func) { PyObject *res; int ret; - PyObject *arg = Py_BuildValue("(O)", member); + PyObject *arg = PyTuple_Pack(1, member); if(arg == NULL) { Py_DECREF(func); return -1; @@ -1346,7 +1346,7 @@ generic_binary_op(PyObject *v, PyObject *w, char *opname) Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } - args = Py_BuildValue("(O)", w); + args = PyTuple_Pack(1, w); if (args == NULL) { Py_DECREF(func); return NULL; @@ -1389,7 +1389,7 @@ half_binop(PyObject *v, PyObject *w, char *opname, binaryfunc thisfunc, return generic_binary_op(v, w, opname); } - args = Py_BuildValue("(O)", w); + args = PyTuple_Pack(1, w); if (args == NULL) { Py_DECREF(coercefunc); return NULL; @@ -1474,7 +1474,7 @@ instance_coerce(PyObject **pv, PyObject **pw) return 1; } /* Has __coerce__ method: call it */ - args = Py_BuildValue("(O)", w); + args = PyTuple_Pack(1, w); if (args == NULL) { return -1; } @@ -1587,7 +1587,7 @@ half_cmp(PyObject *v, PyObject *w) return 2; } - args = Py_BuildValue("(O)", w); + args = PyTuple_Pack(1, w); if (args == NULL) { Py_DECREF(cmp_func); return -2; @@ -1747,7 +1747,7 @@ instance_pow(PyObject *v, PyObject *w, PyObject *z) func = PyObject_GetAttrString(v, "__pow__"); if (func == NULL) return NULL; - args = Py_BuildValue("(OO)", w, z); + args = PyTuple_Pack(2, w, z); if (args == NULL) { Py_DECREF(func); return NULL; @@ -1786,7 +1786,7 @@ instance_ipow(PyObject *v, PyObject *w, PyObject *z) PyErr_Clear(); return instance_pow(v, w, z); } - args = Py_BuildValue("(OO)", w, z); + args = PyTuple_Pack(2, w, z); if (args == NULL) { Py_DECREF(func); return NULL; @@ -1859,7 +1859,7 @@ half_richcompare(PyObject *v, PyObject *w, int op) return res; } - args = Py_BuildValue("(O)", w); + args = PyTuple_Pack(1, w); if (args == NULL) { Py_DECREF(method); return NULL; |