Message89626
It is sometimes useful to be able to swap the contents of two lists and
this patch provides a way to do so using the fastest way possible.
> a = [1, 2]
> b = [3]
> id(a), id(b)
(100, 101)
> a.swap(b)
> a
[3]
> b
[1, 2]
> id(a), id(b)
(100, 101)
One application of this is to make help a performance problem when one
wants to upgrade a list instance into a subclass instance.
orglist = rawlist_from_server()
mylist = ListSubclass(orglist)
This involves copying duplicating the list, and then discarding, which
can take a while for long lists. Much faster is using>
mylist = ListSubclass()
mulist.swap(orglist)
We are using this extension within CCP to decoratate database queries
from our database engine, that are returned as python lists. The
performance gained by shaving off this extra list duplication can be
significant for large data sets.
to change a list, into a |
|
Date |
User |
Action |
Args |
2009-06-23 13:12:49 | kristjan.jonsson | set | recipients:
+ kristjan.jonsson |
2009-06-23 13:12:49 | kristjan.jonsson | set | messageid: <1245762769.52.0.940605508616.issue6326@psf.upfronthosting.co.za> |
2009-06-23 13:12:47 | kristjan.jonsson | link | issue6326 messages |
2009-06-23 13:12:46 | kristjan.jonsson | create | |
|