diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-01-03 01:01:42 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-01-03 01:01:42 (GMT) |
commit | 865a0f621fae0a63f0db186d9b7f30d1cebfa1de (patch) | |
tree | d7a95e54381e1729f431896a6b2812b63a39d8f2 /Python | |
parent | 6f7c0ae46d66593b4ca0f248b94b9e1d567114bb (diff) | |
download | cpython-865a0f621fae0a63f0db186d9b7f30d1cebfa1de.zip cpython-865a0f621fae0a63f0db186d9b7f30d1cebfa1de.tar.gz cpython-865a0f621fae0a63f0db186d9b7f30d1cebfa1de.tar.bz2 |
Optimize _PyFunction_FastCallDict() when kwargs is {}
Issue #28839: Optimize _PyFunction_FastCallDict() when kwargs is an empty
dictionary, avoid the creation of an useless empty tuple.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 5519ac7..cd95642 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5040,9 +5040,9 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, } } - if (kwargs != NULL) { + nk = (kwargs != NULL) ? PyDict_GET_SIZE(kwargs) : 0; + if (nk != 0) { Py_ssize_t pos, i; - nk = PyDict_GET_SIZE(kwargs); kwtuple = PyTuple_New(2 * nk); if (kwtuple == NULL) { @@ -5052,6 +5052,9 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, k = &PyTuple_GET_ITEM(kwtuple, 0); pos = i = 0; while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { + /* We must hold strong references because keyword arguments can be + indirectly modified while the function is called: + see issue #2016 and test_extcall */ Py_INCREF(k[i]); Py_INCREF(k[i+1]); i += 2; @@ -5061,7 +5064,6 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, else { kwtuple = NULL; k = NULL; - nk = 0; } kwdefs = PyFunction_GET_KW_DEFAULTS(func); |