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) self._val_call = (val, val_call)
def impl_is_optiondescription(self): def impl_is_optiondescription(self):
#FIXME deplacer dans OpenDescription ? return False
return self.__class__.__name__ in ['OptionDescription',
'DynOptionDescription',
'SynDynOptionDescription',
'MasterSlaves']
def impl_is_dynoptiondescription(self): def impl_is_dynoptiondescription(self):
return self.__class__.__name__ in ['DynOptionDescription', return False
'SynDynOptionDescription']
def impl_getname(self): def impl_getname(self):
return self._name return self._name

View File

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