diff Python/bltinmodule.c @ 56750:6e4d8968e246 legacy-trunk

Warn against replacing PyNumber_Add with PyNumber_InPlaceAdd in sum
author Mark Dickinson <dickinsm@gmail.com>
date Mon, 26 Oct 2009 14:18:44 +0000
parents 37f5d1785bb3
children 349b97ff4c2b
line wrap: on
line diff
--- a/Python/bltinmodule.c	Mon Oct 26 11:59:30 2009 +0000
+++ b/Python/bltinmodule.c	Mon Oct 26 14:18:44 2009 +0000
@@ -2350,6 +2350,15 @@
 			}
 			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);