diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-09-10 16:31:01 +0300 |
---|---|---|
committer | Dino Viehland <dinoviehland@gmail.com> | 2019-09-10 14:31:01 +0100 |
commit | 88bdb9280b251d753f1b1c8d9183de0fff003622 (patch) | |
tree | c8a96f484735cc1757ceda1aabfb14df86ea3fcf /Python/bltinmodule.c | |
parent | c1d8c1cb8e90a54a3daaa7fcdb8d6ca7f08d6a73 (diff) | |
download | cpython-88bdb9280b251d753f1b1c8d9183de0fff003622.tar.gz cpython-88bdb9280b251d753f1b1c8d9183de0fff003622.zip |
bpo-36781: Optimize sum() for bools. (#13074)
* Optimize sum() for bools.
* Fix sum([], False).
* Add a NEWS entry.
Diffstat (limited to 'Python/bltinmodule.c')
-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 3b0d64ff14a..d069f2fd261 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); |