better performance in optiondescription creation

This commit is contained in:
Emmanuel Garette 2018-06-25 22:20:24 +02:00
parent b10f02a8e9
commit 79c28038a5
2 changed files with 18 additions and 12 deletions

View File

@ -275,15 +275,10 @@ class Base(object):
self._val_call = (val, val_call)
def impl_is_optiondescription(self):
#FIXME deplacer dans OpenDescription ?
return self.__class__.__name__ in ['OptionDescription',
'DynOptionDescription',
'SynDynOptionDescription',
'MasterSlaves']
return False
def impl_is_dynoptiondescription(self):
return self.__class__.__name__ in ['DynOptionDescription',
'SynDynOptionDescription']
return False
def impl_getname(self):
return self._name

View File

@ -393,11 +393,12 @@ class OptionDescription(OptionDescriptionWalk):
if child.impl_is_dynoptiondescription():
dynopt_names.append(name)
#better performance like this
valid_child = copy(child_names)
valid_child.sort()
children_ = (tuple(child_names), tuple(children))
# better performance like this
child_names.sort()
old = None
for child in valid_child:
for child in child_names:
if child == old:
raise ConflictError(_('duplicate option name: '
'"{0}"').format(child))
@ -407,11 +408,21 @@ class OptionDescription(OptionDescriptionWalk):
raise ConflictError(_('the option\'s name "{}" start as '
'the dynoptiondescription\'s name "{}"').format(child, dynopt))
old = child
self._children = (tuple(child_names), tuple(children))
self._children = children_
self._cache_consistencies = None
# the group_type is useful for filtering OptionDescriptions in a config
self._group_type = groups.default
def impl_is_optiondescription(self):
return self.__class__.__name__ in ['OptionDescription',
'DynOptionDescription',
'SynDynOptionDescription',
'MasterSlaves']
def impl_is_dynoptiondescription(self):
return self.__class__.__name__ in ['DynOptionDescription',
'SynDynOptionDescription']
def impl_is_master_slaves(self, *args, **kwargs):
return False