[Python-checkins] r75714 - python/trunk/Python/bltinmodule.c

mark.dickinson python-checkins at python.org
Mon Oct 26 15:18:44 CET 2009


Author: mark.dickinson
Date: Mon Oct 26 15:18:44 2009
New Revision: 75714

Log:
Warn against replacing PyNumber_Add with PyNumber_InPlaceAdd in sum

Modified:
   python/trunk/Python/bltinmodule.c

Modified: python/trunk/Python/bltinmodule.c
==============================================================================
--- python/trunk/Python/bltinmodule.c	(original)
+++ python/trunk/Python/bltinmodule.c	Mon Oct 26 15:18:44 2009
@@ -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);


More information about the Python-checkins mailing list