From c70f1f3d343c5583b41da1a8e1eae8163064a1bd Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Tue, 26 Mar 2013 12:05:05 +0100
Subject: [PATCH] getSecurityUidDictAndRoleColumnDict micro-optimisation

try..except is significantly slower than getattr with default value when
an exception is raised.
defaultdict is faster than calling setdefault.
The two other try..except blocks need more careful analysis of typical
hit-rates to tell if they are optimal.
---
 product/ERP5Catalog/CatalogTool.py | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/product/ERP5Catalog/CatalogTool.py b/product/ERP5Catalog/CatalogTool.py
index d1a5a30669..9919305c5d 100644
--- a/product/ERP5Catalog/CatalogTool.py
+++ b/product/ERP5Catalog/CatalogTool.py
@@ -26,6 +26,7 @@
 #
 ##############################################################################
 
+from collections import defaultdict
 from Products.CMFCore.CatalogTool import CatalogTool as CMFCoreCatalogTool
 from Products.ZSQLCatalog.ZSQLCatalog import ZCatalog
 from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
@@ -526,15 +527,10 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
             # dtml instead ? ... yes, but how to be bw compatible ?
             allowedRolesAndUsers = [sqlquote(role) for role in allowedRolesAndUsers]
 
-            security_uid_dict = dict()
+            security_uid_dict = defaultdict(list)
             for brain in method(security_roles_list=allowedRolesAndUsers):
-              try:
-                local_roles_group_id = brain.local_roles_group_id
-              except AttributeError:
-                # backwards compatability in cases when catalog use default schema
-                local_roles_group_id = ''
-              security_uid_dict.setdefault(local_roles_group_id,
-                  []).append(brain.uid)
+              security_uid_dict[getattr(brain, 'local_roles_group_id', '')
+                ].append(brain.uid)
 
           security_uid_cache[cache_key] = security_uid_dict
       else:
-- 
2.30.9