Optimization of __len__() in cgi.py

Georg Brandl g.brandl-nospam at gmx.net
Wed Aug 16 11:35:51 EDT 2006


Bob Kline wrote:
> I have a suggestion for speeding up the performance of code like this:
> 
> fields = cgi.FieldStorage()
> if fields: ...
> 
> which, as it turns out, invokes FieldStorage.__len__(), which in turn
> calls FieldStorage.keys(), which builds a list of keys by hand, taking
> several minutes for large forms.  This implementation of keys() reduces
> the amount of time taken by several orders of magnitude:
> 
>     def keys(self):
>         return {}.fromkeys([i.name for i in self.list]).keys()
> 
> Is there a better place for submitting suggestions like this?

Post a RFE to the Python Tracker at 
http://sourceforge.net/tracker/?group_id=5470&atid=355470

If you want, assign it to me (gbrandl).

Georg



More information about the Python-list mailing list