Commit a5f950b3 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Cosmetic: Use faster and simpler defaultdict() rather than setdefault().

parent 4b0b4ec4
......@@ -32,6 +32,7 @@ from __future__ import absolute_import
import sys
import imp
import collections
from Products.ERP5.ERP5Site import getSite
from Products.ERP5Type.Globals import get_request
......@@ -74,7 +75,7 @@ class ComponentDynamicPackage(ModuleType):
self._namespace_prefix = namespace + '.'
self._portal_type = portal_type
self.__version_suffix_len = len('_version')
self.__registry_dict = {}
self.__registry_dict = collections.defaultdict(dict)
# Add this module to sys.path for future imports
sys.modules[namespace] = self
......@@ -124,9 +125,8 @@ class ComponentDynamicPackage(ModuleType):
# beforehand
if version in version_priority_set:
reference = component.getReference(validated_only=True)
self.__registry_dict.setdefault(reference, {})[version] = (
component.getId(),
component._p_oid)
self.__registry_dict[reference][version] = (component.getId(),
component._p_oid)
return self.__registry_dict
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment