summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-03-25 06:53:47 +0000
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-03-25 06:53:47 +0000
commit0bbe7379ee3e2cb290f9c9e841bb2f1457e14b16 (patch)
tree2146f36c48ab87c2eb8bd558b071266bd2ac6aef /django/utils
parent15fb61c62ce403bc2ba7f63c5f519a988ce2c5d2 (diff)
[1.3.X] Fixed #17634 -- Optimized the performance of MultiValueDict by using append instead of copy and by minimizing the number of dict lookups. Backport of r17464 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@17807 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/datastructures.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 7425ea2ce2..33cc2450c2 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -319,17 +319,20 @@ class MultiValueDict(dict):
def setdefault(self, key, default=None):
if key not in self:
self[key] = default
+ return default
return self[key]
- def setlistdefault(self, key, default_list=()):
+ def setlistdefault(self, key, default_list=None):
if key not in self:
+ if default_list is None:
+ default_list = []
self.setlist(key, default_list)
+ return default_list
return self.getlist(key)
def appendlist(self, key, value):
"""Appends an item to the internal list associated with key."""
- self.setlistdefault(key, [])
- super(MultiValueDict, self).__setitem__(key, self.getlist(key) + [value])
+ self.setlistdefault(key).append(value)
def items(self):
"""
@@ -378,15 +381,15 @@ class MultiValueDict(dict):
other_dict = args[0]
if isinstance(other_dict, MultiValueDict):
for key, value_list in other_dict.lists():
- self.setlistdefault(key, []).extend(value_list)
+ self.setlistdefault(key).extend(value_list)
else:
try:
for key, value in other_dict.items():
- self.setlistdefault(key, []).append(value)
+ self.setlistdefault(key).append(value)
except TypeError:
raise ValueError("MultiValueDict.update() takes either a MultiValueDict or dictionary")
for key, value in kwargs.iteritems():
- self.setlistdefault(key, []).append(value)
+ self.setlistdefault(key).append(value)
class DotExpandedDict(dict):
"""