[Python-Dev] Re: [Python-checkins] python/dist/src/Python
bltinmodule.c, 2.292.10.1, 2.292.10.2
Guido van Rossum
guido at python.org
Sat Oct 25 17:18:42 EDT 2003
> Modified Files:
> Tag: release23-maint
> bltinmodule.c
> Log Message:
> changed builtin_sum to use PyNumber_InPlaceAdd -- unchanged semantics but
> fixes performance bug with sum(lotsoflists, []).
I think this ought to be reverted, both in 2.3 and 2.4. Consider this code:
empty = []
for i in range(10):
print sum([[x] for x in range(i)], empty)
The output used to be:
[]
[0]
[0, 1]
[0, 1, 2]
[0, 1, 2, 3]
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4, 5]
[0, 1, 2, 3, 4, 5, 6]
[0, 1, 2, 3, 4, 5, 6, 7]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
But now it is:
[]
[0]
[0, 0, 1]
[0, 0, 1, 0, 1, 2]
[0, 0, 1, 0, 1, 2, 0, 1, 2, 3]
[0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4]
[0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5]
[0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6]
[0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 7]
[0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8]
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list