mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
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.
This commit is contained in:
parent
ca37661a69
commit
ea837931cf
3 changed files with 182 additions and 160 deletions
|
@ -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},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue