This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kristjan.jonsson
Recipients kristjan.jonsson
Date 2009-06-23.13:12:45
SpamBayes Score 2.5887577e-05
Marked as misclassified No
Message-id <1245762769.52.0.940605508616.issue6326@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2009-06-23 13:12:49kristjan.jonssonsetrecipients: + kristjan.jonsson
2009-06-23 13:12:49kristjan.jonssonsetmessageid: <1245762769.52.0.940605508616.issue6326@psf.upfronthosting.co.za>
2009-06-23 13:12:47kristjan.jonssonlinkissue6326 messages
2009-06-23 13:12:46kristjan.jonssoncreate