From c195bea0e1237455795f1cd69636c5e0bcba15a5 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Mon, 14 Jan 2008 11:18:19 +0100 Subject: [PATCH] cleanup and faster kw arg splitting in __Pyx_GetStarArgs --- Cython/Compiler/Nodes.py | 47 +++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 7f9807cb..86e0d01a 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -3347,7 +3347,7 @@ static int __Pyx_GetStarArgs( PyObject **kwds2, char rqd_kwds[]) { - PyObject *x = 0, *args1 = 0, *kwds1 = 0; + PyObject *s = 0, *x = 0, *args1 = 0, *kwds1 = 0; int i; char **p; @@ -3376,14 +3376,9 @@ static int __Pyx_GetStarArgs( args1 = *args; 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(); if (!kwds1) goto bad; @@ -3391,30 +3386,41 @@ static int __Pyx_GetStarArgs( if (!*kwds2) goto bad; 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 (PyDict_SetItemString(kwds1, *p, x) < 0) + if (PyDict_SetItem(kwds1, s, x) < 0) goto bad; - if (PyDict_DelItemString(*kwds2, *p) < 0) + if (PyDict_DelItem(*kwds2, s) < 0) goto bad; } else if (rqd_kwds && rqd_kwds[i]) goto missing_kwarg; + Py_DECREF(s); } + s = 0; } else { - *kwds2 = PyDict_New(); - if (!*kwds2) - goto bad; + kwds1 = *kwds; + Py_INCREF(kwds1); + if (rqd_kwds) { + for (i = 0, p = kwd_list; *p; i++, p++) + if (rqd_kwds[i] && !PyDict_GetItemString(kwds1, *p)) + goto missing_kwarg; + } } } else { - kwds1 = *kwds; - Py_XINCREF(kwds1); - if (rqd_kwds && *kwds) + if (rqd_kwds) { for (i = 0, p = kwd_list; *p; i++, p++) - if (rqd_kwds[i] && !PyDict_GetItemString(*kwds, *p)) - goto missing_kwarg; + if (rqd_kwds[i]) + goto missing_kwarg; + } + if (kwds2) { + *kwds2 = PyDict_New(); + if (!*kwds2) + goto bad; + } } *args = args1; @@ -3424,6 +3430,7 @@ missing_kwarg: PyErr_Format(PyExc_TypeError, "required keyword argument '%s' is missing", *p); bad: + Py_XDECREF(s); Py_XDECREF(args1); Py_XDECREF(kwds1); if (args2) { -- 2.26.2