[Checkins] SVN: Sandbox/faassen/iface/src/iface/mapping.py Avoid creating a slice by using a list from the start and popping
Martijn Faassen
faassen at startifact.com
Wed Jan 6 19:20:43 EST 2010
Log message for revision 107758:
Avoid creating a slice by using a list from the start and popping
the last key off.
Changed:
U Sandbox/faassen/iface/src/iface/mapping.py
-=-
Modified: Sandbox/faassen/iface/src/iface/mapping.py
===================================================================
--- Sandbox/faassen/iface/src/iface/mapping.py 2010-01-07 00:11:03 UTC (rev 107757)
+++ Sandbox/faassen/iface/src/iface/mapping.py 2010-01-07 00:20:43 UTC (rev 107758)
@@ -50,22 +50,24 @@
def __setitem__(self, key, value):
arity = MapKey(len(key))
- key = (arity,) + tuple(key)
+ key = [arity] + list(key)
+ last_key = key.pop()
map = self._by_arity
- for k in key[:-1]:
+ for k in key:
submap = dict(map).get(k)
if submap is None:
submap = map[k] = Map()
map = submap
- map[key[-1]] = value
+ map[last_key] = value
def __delitem__(self, key):
arity = MapKey(len(key))
- key = (arity,) + tuple(key)
+ key = [arity] + list(key)
+ last_key = key.pop()
map = self._by_arity
- for k in key[:-1]:
+ for k in key:
map = dict(map)[k]
- del map[key[-1]]
+ del map[last_key]
def __getitem__(self, key):
arity = MapKey(len(key))
More information about the checkins
mailing list