diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-09-10 13:31:01 (GMT) |
---|---|---|
committer | Dino Viehland <dinoviehland@gmail.com> | 2019-09-10 13:31:01 (GMT) |
commit | 88bdb9280b251d753f1b1c8d9183de0fff003622 (patch) | |
tree | c8a96f484735cc1757ceda1aabfb14df86ea3fcf /Python | |
parent | c1d8c1cb8e90a54a3daaa7fcdb8d6ca7f08d6a73 (diff) | |
download | cpython-88bdb9280b251d753f1b1c8d9183de0fff003622.zip cpython-88bdb9280b251d753f1b1c8d9183de0fff003622.tar.gz cpython-88bdb9280b251d753f1b1c8d9183de0fff003622.tar.bz2 |
bpo-36781: Optimize sum() for bools. (#13074)
* Optimize sum() for bools.
* Fix sum([], False).
* Add a NEWS entry.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 3b0d64f..d069f2f 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -2342,7 +2342,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start) return NULL; return PyLong_FromLong(i_result); } - if (PyLong_CheckExact(item)) { + if (PyLong_CheckExact(item) || PyBool_Check(item)) { long b = PyLong_AsLongAndOverflow(item, &overflow); if (overflow == 0 && (i_result >= 0 ? (b <= LONG_MAX - i_result) @@ -2390,7 +2390,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start) Py_DECREF(item); continue; } - if (PyLong_CheckExact(item)) { + if (PyLong_Check(item)) { long value; int overflow; value = PyLong_AsLongAndOverflow(item, &overflow); |