Skip to content

Commit 5e5309d

Browse files
author
lantis63
committed
Small speed up in MethodDispatch
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40335
1 parent ab20193 commit 5e5309d

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

src/utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@ class MethodDispatcher(dict):
1212
multiple keys so accessing any one of the items in the original
1313
list-like object returns the matching value
1414
15-
md = MethodDispatcher({["foo", "bar"]:"baz"})
15+
md = MethodDispatcher({("foo", "bar"):"baz"})
1616
md["foo"] == "baz"
1717
1818
A default value which can be set through the default attribute.
1919
"""
2020

2121
def __init__(self, items=()):
22-
_dictEntries = []
2322
for name,value in items:
2423
if type(name) in (list, tuple, frozenset, set):
2524
for item in name:
26-
_dictEntries.append((item, value))
25+
self[item] = value
2726
else:
28-
_dictEntries.append((name, value))
29-
dict.__init__(self, _dictEntries)
27+
self[name] = value
3028
self.default = None
3129

3230
def __getitem__(self, key):

0 commit comments

Comments
 (0)