[transaction] use set operation in the hook control code
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Mon, 25 Mar 2013 16:35:18 +0100
changeset 8789 465a87e6a89a
parent 8788 194f1418bc7e
child 8790 c3fc17d79e85
[transaction] use set operation in the hook control code We use direct operator on set instead of looping by hand, This simplify the codes.
server/session.py
--- a/server/session.py	Mon Mar 25 16:08:48 2013 +0100
+++ b/server/session.py	Mon Mar 25 16:35:18 2013 +0100
@@ -309,18 +309,15 @@
         """
         changes = set()
         self.pruned_hooks_cache.clear()
+        categories = set(categories)
         if self.hooks_mode is HOOKS_DENY_ALL:
             enabledcats = self.enabled_hook_cats
-            for category in categories:
-                if category in enabledcats:
-                    enabledcats.remove(category)
-                    changes.add(category)
+            changes = enabledcats & categories
+            enabledcats -= changes # changes is small hence faster
         else:
             disabledcats = self.disabled_hook_cats
-            for category in categories:
-                if category not in disabledcats:
-                    disabledcats.add(category)
-                    changes.add(category)
+            changes = categories - disabledcats
+            disabledcats |= changes # changes is small hence faster
         return tuple(changes)
 
     def enable_hook_categories(self, *categories):
@@ -331,18 +328,15 @@
         """
         changes = set()
         self.pruned_hooks_cache.clear()
+        categories = set(categories)
         if self.hooks_mode is HOOKS_DENY_ALL:
             enabledcats = self.enabled_hook_cats
-            for category in categories:
-                if category not in enabledcats:
-                    enabledcats.add(category)
-                    changes.add(category)
+            changes = categories - enabledcats
+            enabledcats |= changes # changes is small hence faster
         else:
             disabledcats = self.disabled_hook_cats
-            for category in categories:
-                if category in disabledcats:
-                    disabledcats.remove(category)
-                    changes.add(category)
+            changes = disabledcats & categories
+            disabledcats -= changes # changes is small hence faster
         return tuple(changes)
 
     def is_hook_category_activated(self, category):