From 88bdb9280b251d753f1b1c8d9183de0fff003622 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 10 Sep 2019 16:31:01 +0300 Subject: bpo-36781: Optimize sum() for bools. (#13074) * Optimize sum() for bools. * Fix sum([], False). * Add a NEWS entry. --- Python/bltinmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 3b0d64ff14..d069f2fd26 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); -- cgit v1.2.1