From 80b91983c97db284ce39a695cc0258902e1d70a9 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Mon, 13 Nov 2017 11:35:04 +0100 Subject: Micro-optimize Symbol.__init__() a bit Chained assignments turn a bunch of LOAD_CONSTs into DUP_TOPs. Shaves ~10% off the runtime of _lookup_sym(). Do the same for Choice.__init__(), just for consistency. Remove an accidental duplicated assigment to 'defaults' too. --- kconfiglib.py | 56 ++++++++++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index 3c9eedb..08f73d9 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -1446,8 +1446,7 @@ class Kconfig(object): node = MenuNode() node.kconfig = self node.item = sym - node.help = None - node.list = None + node.help = node.list = None node.parent = parent node.filename = self._filename node.linenr = self._linenr @@ -1478,8 +1477,7 @@ class Kconfig(object): elif t0 == _T_IF: node = MenuNode() - node.item = None - node.prompt = None + node.item = node.prompt = None node.parent = parent node.filename = self._filename node.linenr = self._linenr @@ -2736,28 +2734,22 @@ class Symbol(object): self.nodes = [] - self.user_value = None - - # See Kconfig._build_dep() - self._dependents = set() - - # Cached values - + self.user_value = \ + self.choice = \ + self.env_var = \ self._cached_str_val = self._cached_tri_val = self._cached_vis = \ - self._cached_assignable = None + self._cached_assignable = None - # Flags + # _write_to_conf is calculated along with the value. If True, the + # Symbol gets a .config entry. - self.choice = None - self.env_var = None - self.is_allnoconfig_y = False - - self._was_set = False - - # Should the symbol get an entry in .config? Calculated along with the - # value. + self.is_allnoconfig_y = \ + self._was_set = \ self._write_to_conf = False + # See Kconfig._build_dep() + self._dependents = set() + def _get_assignable(self): """ Worker function for the 'assignable' attribute. @@ -3195,28 +3187,24 @@ class Choice(object): # don't need defaults: # kconfig - self.name = None self.orig_type = UNKNOWN self.syms = [] self.defaults = [] self.nodes = [] - self.user_value = self.user_selection = None - - # Checked by _make_depend_on(). Just set it to avoid having to - # special-case choices. - self.is_constant = False - # See Kconfig._build_dep() - self._dependents = set() - - self.defaults = [] - - # Cached values + self.name = \ + self.user_value = self.user_selection = \ self._cached_vis = self._cached_assignable = None + self._cached_selection = _NO_CACHED_SELECTION - self.is_optional = False + # is_constant is checked by _make_depend_on(). Just set it to avoid + # having to special-case choices. + self.is_constant = self.is_optional = False + + # See Kconfig._build_dep() + self._dependents = set() def _get_assignable(self): """ -- cgit v1.2.3