Commit c195bea0 authored by Stefan Behnel's avatar Stefan Behnel

cleanup and faster kw arg splitting in __Pyx_GetStarArgs

parent 1f35c14d
...@@ -3347,7 +3347,7 @@ static int __Pyx_GetStarArgs( ...@@ -3347,7 +3347,7 @@ static int __Pyx_GetStarArgs(
PyObject **kwds2, PyObject **kwds2,
char rqd_kwds[]) char rqd_kwds[])
{ {
PyObject *x = 0, *args1 = 0, *kwds1 = 0; PyObject *s = 0, *x = 0, *args1 = 0, *kwds1 = 0;
int i; int i;
char **p; char **p;
...@@ -3377,13 +3377,8 @@ static int __Pyx_GetStarArgs( ...@@ -3377,13 +3377,8 @@ static int __Pyx_GetStarArgs(
Py_INCREF(args1); Py_INCREF(args1);
} }
if (rqd_kwds && !*kwds)
for (i = 0, p = kwd_list; *p; i++, p++)
if (rqd_kwds[i])
goto missing_kwarg;
if (kwds2) {
if (*kwds) { if (*kwds) {
if (kwds2) {
kwds1 = PyDict_New(); kwds1 = PyDict_New();
if (!kwds1) if (!kwds1)
goto bad; goto bad;
...@@ -3391,31 +3386,42 @@ static int __Pyx_GetStarArgs( ...@@ -3391,31 +3386,42 @@ static int __Pyx_GetStarArgs(
if (!*kwds2) if (!*kwds2)
goto bad; goto bad;
for (i = 0, p = kwd_list; *p; i++, p++) { for (i = 0, p = kwd_list; *p; i++, p++) {
x = PyDict_GetItemString(*kwds, *p); s = PyString_FromString(*p);
x = PyDict_GetItem(*kwds, s);
if (x) { if (x) {
if (PyDict_SetItemString(kwds1, *p, x) < 0) if (PyDict_SetItem(kwds1, s, x) < 0)
goto bad; goto bad;
if (PyDict_DelItemString(*kwds2, *p) < 0) if (PyDict_DelItem(*kwds2, s) < 0)
goto bad; goto bad;
} }
else if (rqd_kwds && rqd_kwds[i]) else if (rqd_kwds && rqd_kwds[i])
goto missing_kwarg; goto missing_kwarg;
Py_DECREF(s);
} }
s = 0;
} }
else { else {
*kwds2 = PyDict_New(); kwds1 = *kwds;
if (!*kwds2) Py_INCREF(kwds1);
goto bad; if (rqd_kwds) {
for (i = 0, p = kwd_list; *p; i++, p++)
if (rqd_kwds[i] && !PyDict_GetItemString(kwds1, *p))
goto missing_kwarg;
}
} }
} }
else { else {
kwds1 = *kwds; if (rqd_kwds) {
Py_XINCREF(kwds1);
if (rqd_kwds && *kwds)
for (i = 0, p = kwd_list; *p; i++, p++) for (i = 0, p = kwd_list; *p; i++, p++)
if (rqd_kwds[i] && !PyDict_GetItemString(*kwds, *p)) if (rqd_kwds[i])
goto missing_kwarg; goto missing_kwarg;
} }
if (kwds2) {
*kwds2 = PyDict_New();
if (!*kwds2)
goto bad;
}
}
*args = args1; *args = args1;
*kwds = kwds1; *kwds = kwds1;
...@@ -3424,6 +3430,7 @@ missing_kwarg: ...@@ -3424,6 +3430,7 @@ missing_kwarg:
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"required keyword argument '%s' is missing", *p); "required keyword argument '%s' is missing", *p);
bad: bad:
Py_XDECREF(s);
Py_XDECREF(args1); Py_XDECREF(args1);
Py_XDECREF(kwds1); Py_XDECREF(kwds1);
if (args2) { if (args2) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment