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 | |
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')
-rw-r--r-- | Objects/classobject.c | 28 | ||||
-rw-r--r-- | Objects/complexobject.c | 4 | ||||
-rw-r--r-- | Objects/fileobject.c | 4 | ||||
-rw-r--r-- | Objects/typeobject.c | 21 |
4 files changed, 28 insertions, 29 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; diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 96fa33d..c29d48d 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -439,7 +439,7 @@ complex_divmod(PyComplexObject *v, PyComplexObject *w) mod = c_diff(v->cval, c_prod(w->cval, div)); d = PyComplex_FromCComplex(div); m = PyComplex_FromCComplex(mod); - z = Py_BuildValue("(OO)", d, m); + z = PyTuple_Pack(2, d, m); Py_XDECREF(d); Py_XDECREF(m); return z; @@ -865,7 +865,7 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (f == NULL) PyErr_Clear(); else { - PyObject *args = Py_BuildValue("()"); + PyObject *args = PyTuple_New(0); if (args == NULL) return NULL; r = PyEval_CallObject(f, args); diff --git a/Objects/fileobject.c b/Objects/fileobject.c index d7c9da5..6f90fb9 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -1227,7 +1227,7 @@ PyFile_GetLine(PyObject *f, int n) if (reader == NULL) return NULL; if (n <= 0) - args = Py_BuildValue("()"); + args = PyTuple_New(0); else args = Py_BuildValue("(i)", n); if (args == NULL) { @@ -2104,7 +2104,7 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags) Py_DECREF(writer); return -1; } - args = Py_BuildValue("(O)", value); + args = PyTuple_Pack(1, value); if (args == NULL) { Py_DECREF(value); Py_DECREF(writer); diff --git a/Objects/typeobject.c b/Objects/typeobject.c index bb498e4..dcb43e5 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -163,7 +163,7 @@ mro_subclasses(PyTypeObject *type, PyObject* temp) } else { PyObject* tuple; - tuple = Py_BuildValue("OO", subclass, old_mro); + tuple = PyTuple_Pack(2, subclass, old_mro); Py_DECREF(old_mro); if (!tuple) return -1; @@ -258,8 +258,8 @@ type_set_bases(PyTypeObject *type, PyObject *value, void *context) for (i = 0; i < PyList_Size(temp); i++) { PyTypeObject* cls; PyObject* mro; - PyArg_ParseTuple(PyList_GET_ITEM(temp, i), - "OO", &cls, &mro); + PyArg_UnpackTuple(PyList_GET_ITEM(temp, i), + "", 2, 2, &cls, &mro); Py_DECREF(cls->tp_mro); cls->tp_mro = mro; Py_INCREF(cls->tp_mro); @@ -1606,7 +1606,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) /* Adjust for empty tuple bases */ if (nbases == 0) { - bases = Py_BuildValue("(O)", &PyBaseObject_Type); + bases = PyTuple_Pack(1, &PyBaseObject_Type); if (bases == NULL) return NULL; nbases = 1; @@ -1650,7 +1650,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) /* Make it into a tuple */ if (PyString_Check(slots)) - slots = Py_BuildValue("(O)", slots); + slots = PyTuple_Pack(1, slots); else slots = PySequence_Tuple(slots); if (slots == NULL) { @@ -2644,8 +2644,7 @@ reduce_2(PyObject *obj) PyTuple_SET_ITEM(args2, i+1, v); } - res = Py_BuildValue("(OOOOO)", - newobj, args2, state, listitems, dictitems); + res = PyTuple_Pack(5, newobj, args2, state, listitems, dictitems); end: Py_XDECREF(cls); @@ -3142,7 +3141,7 @@ PyType_Ready(PyTypeObject *type) if (base == NULL) bases = PyTuple_New(0); else - bases = Py_BuildValue("(O)", base); + bases = PyTuple_Pack(1, base); if (bases == NULL) goto error; type->tp_bases = bases; @@ -4127,7 +4126,7 @@ slot_sq_contains(PyObject *self, PyObject *value) func = lookup_maybe(self, "__contains__", &contains_str); if (func != NULL) { - args = Py_BuildValue("(O)", value); + args = PyTuple_Pack(1, value); if (args == NULL) res = NULL; else { @@ -4342,7 +4341,7 @@ half_compare(PyObject *self, PyObject *other) PyErr_Clear(); } else { - args = Py_BuildValue("(O)", other); + args = PyTuple_Pack(1, other); if (args == NULL) res = NULL; else { @@ -4571,7 +4570,7 @@ half_richcompare(PyObject *self, PyObject *other, int op) Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } - args = Py_BuildValue("(O)", other); + args = PyTuple_Pack(1, other); if (args == NULL) res = NULL; else { |