inotify: dic.setdefault(k, d) ; v = dic[k] --> v = dic.setdefault(k, d)
authorNicolas Dumazet <nicdumz.commits@gmail.com>
Fri, 08 May 2009 16:28:52 +0900
changeset 8384 483d9b2103da
parent 8383 dcfdcb51ac5c
child 8385 1536501ade62
inotify: dic.setdefault(k, d) ; v = dic[k] --> v = dic.setdefault(k, d) dict.setdefault sets a default value, but also returns the dict.get result. Getting the value on the next instruction was redundant.
hgext/inotify/server.py
--- a/hgext/inotify/server.py	Fri May 08 16:40:39 2009 +0900
+++ b/hgext/inotify/server.py	Fri May 08 16:28:52 2009 +0900
@@ -214,8 +214,7 @@
     def dir(self, tree, path):
         if path:
             for name in path.split('/'):
-                tree.setdefault(name, {})
-                tree = tree[name]
+                tree = tree.setdefault(name, {})
         return tree
 
     def lookup(self, path, tree):
@@ -438,8 +437,7 @@
         self.updatestatus(wpath, None)
 
     def schedule_work(self, wpath, evt):
-        self.eventq.setdefault(wpath, [])
-        prev = self.eventq[wpath]
+        prev = self.eventq.setdefault(wpath, [])
         try:
             if prev and evt == 'm' and prev[-1] in 'cm':
                 return