[
http://issues.apache.org/jira/browse/MODPYTHON-93?page=comments#action_12358568
]
Jim Gallacher commented on MODPYTHON-93:
----------------------------------------
The FieldStorage methods get, getitems, has_key, __len__, getfirst and getlist
*all* iterate over the complete list of fields each time they are called and so
would all benefit from some kind of indexing scheme. Here is a bit of code that
will give you some idea of what I have in mind.
class FieldStorage:
def __init__():
self.index = {} # holds references to the Field objects and can be
used as an index.
self.list = []
... blah blah blah ...
... create the field and get it's name ...
self.list.append(field)
if name in self.index:
self.index[name].append(field)
else:
self.index[name] = [field,]
def __getitem__(self, key):
if key not in self.index:
raise KeyError, key
found = self.index[key]
if len(found) == 1:
return found[0]
else:
return found
The other FieldStorage methods would need to be refactored to take advantage of
the index.
> Improve util.FieldStorage efficiency
> ------------------------------------
>
> Key: MODPYTHON-93
> URL: http://issues.apache.org/jira/browse/MODPYTHON-93
> Project: mod_python
> Type: Improvement
> Components: core
> Versions: 3.3
> Reporter: Jim Gallacher
> Assignee: Jim Gallacher
> Priority: Minor
>
> Form fields are saved as a list in a FieldStorage class instance. The class
> implements a __getitem__ method to provide dict-like behaviour. This method
> iterates over the complete list for every call to __getitem__. Applications
> that need to access all the fields when processing the form will show O(n^2)
> behaviour where n == the number of form fields. This overhead could be
> avoided by creating a dict (to use as an index) when the FieldStorage
> instance is created.
> Mike Looijmans has been investigating StringField and Field as well. It is
> probably reasonable to include information on his work in this issue as well,
> so that we can consider all of these efficiency issues in toto.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira