diff options
author | Christian Heimes <christian@cheimes.de> | 2008-02-26 17:23:51 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-02-26 17:23:51 (GMT) |
commit | ea837931cf393aa0373ccfa1849b2a3d6e3cc6ea (patch) | |
tree | ec22401b4627548c98b364f36f01013b11d563b9 /Modules | |
parent | ca37661a69a10d70536b779e3a6ca387340b0ecd (diff) | |
download | cpython-ea837931cf393aa0373ccfa1849b2a3d6e3cc6ea.zip cpython-ea837931cf393aa0373ccfa1849b2a3d6e3cc6ea.tar.gz cpython-ea837931cf393aa0373ccfa1849b2a3d6e3cc6ea.tar.bz2 |
Patch #1691070 from Roger Upole: Speed up PyArg_ParseTupleAndKeywords() and improve error msg
My tests don't show the promised speed up of 10%. The code is as fast as the old code for simple cases and slightly faster for complex cases with several of args and kwargs. But the patch simplifies the code, too.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapimodule.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 8a0f479..40eaaad 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -306,6 +306,22 @@ getargs_tuple(PyObject *self, PyObject *args) return Py_BuildValue("iii", a, b, c); } +/* test PyArg_ParseTupleAndKeywords */ +static PyObject *getargs_keywords(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *keywords[] = {"arg1","arg2","arg3","arg4","arg5", NULL}; + static char *fmt="(ii)i|(i(ii))(iii)i"; + int int_args[10]={-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords, + &int_args[0], &int_args[1], &int_args[2], &int_args[3], &int_args[4], + &int_args[5], &int_args[6], &int_args[7], &int_args[8], &int_args[9])) + return NULL; + return Py_BuildValue("iiiiiiiiii", + int_args[0], int_args[1], int_args[2], int_args[3], int_args[4], + int_args[5], int_args[6], int_args[7], int_args[8], int_args[9]); +} + /* Functions to call PyArg_ParseTuple with integer format codes, and return the result. */ @@ -732,6 +748,8 @@ static PyMethodDef TestMethods[] = { PyDoc_STR("This is a pretty normal docstring.")}, {"getargs_tuple", getargs_tuple, METH_VARARGS}, + {"getargs_keywords", (PyCFunction)getargs_keywords, + METH_VARARGS|METH_KEYWORDS}, {"getargs_b", getargs_b, METH_VARARGS}, {"getargs_B", getargs_B, METH_VARARGS}, {"getargs_H", getargs_H, METH_VARARGS}, |