diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-10-26 14:18:44 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-10-26 14:18:44 (GMT) |
commit | 0e0e21530821e7b3218fca3fa7a286ed6088eceb (patch) | |
tree | 33fc830139d08f49a3ce902cbabeab26569262d7 /Python | |
parent | 828b39865a0c84741e0362dcea0750344733db69 (diff) | |
download | cpython-0e0e21530821e7b3218fca3fa7a286ed6088eceb.zip cpython-0e0e21530821e7b3218fca3fa7a286ed6088eceb.tar.gz cpython-0e0e21530821e7b3218fca3fa7a286ed6088eceb.tar.bz2 |
Warn against replacing PyNumber_Add with PyNumber_InPlaceAdd in sum
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 1f25d5d..c060770 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -2350,6 +2350,15 @@ builtin_sum(PyObject *self, PyObject *args) } break; } + /* It's tempting to use PyNumber_InPlaceAdd instead of + PyNumber_Add here, to avoid quadratic running time + when doing 'sum(list_of_lists, [])'. However, this + would produce a change in behaviour: a snippet like + + empty = [] + sum([[x] for x in range(10)], empty) + + would change the value of empty. */ temp = PyNumber_Add(result, item); Py_DECREF(result); Py_DECREF(item); |