]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 75714 via svnmerge from
authorMark Dickinson <dickinsm@gmail.com>
Mon, 26 Oct 2009 14:19:42 +0000 (14:19 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Mon, 26 Oct 2009 14:19:42 +0000 (14:19 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r75714 | mark.dickinson | 2009-10-26 14:18:44 +0000 (Mon, 26 Oct 2009) | 1 line

  Warn against replacing PyNumber_Add with PyNumber_InPlaceAdd in sum
........

Python/bltinmodule.c

index ab6049cabff35a14cad3c372655f3ce4d13aaf82..297c795ca372636cba448fe0b48552df9c3da01f 100644 (file)
@@ -1958,6 +1958,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);