mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
bpo-36781: Optimize sum() for bools. (#13074)
* Optimize sum() for bools. * Fix sum([], False). * Add a NEWS entry.
This commit is contained in:
parent
c1d8c1cb8e
commit
88bdb9280b
3 changed files with 24 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue