From: Bruno Haible Date: Fri, 12 Apr 2024 22:10:44 +0000 (+0200) Subject: gnulib-tool.py: Optimize. X-Git-Tag: v1.0~109 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=27c5b31a42ccd5353ccff09d46dbaa0d105f0f0b;p=gnulib.git gnulib-tool.py: Optimize. * pygnulib/GLConfig.py (GLConfig.update, GLConfig.update_key): Avoid useless cloning of dictionaries. --- diff --git a/ChangeLog b/ChangeLog index b25819a4aa..212a78b305 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-04-12 Bruno Haible + + gnulib-tool.py: Optimize. + * pygnulib/GLConfig.py (GLConfig.update, GLConfig.update_key): Avoid + useless cloning of dictionaries. + 2024-04-12 Bruno Haible gnulib-tool.py: Implement --no-conditional-dependencies correctly. diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py index e938b30a5e..515047d3f0 100644 --- a/pygnulib/GLConfig.py +++ b/pygnulib/GLConfig.py @@ -275,21 +275,27 @@ class GLConfig: if type(dictionary) is not GLConfig: raise TypeError('dictionary must be a GLConfig, not %s' % type(dictionary).__name__) - dictionary = dict(dictionary.table) + dictionary = dictionary.table result = dict() for key in dictionary: src = self.table[key] dest = dictionary[key] - result[key] = src - if src != dest: + # Merge src and dest into a single value. + if src == dest: + value = src + else: if self.isdefault(key, src): - result[key] = dest + value = dest else: # if not self.isdefault(key, src) - if not self.isdefault(key, dest): + if self.isdefault(key, dest): + value = src + else: # if not self.isdefault(key, dest) if key in ['modules', 'avoids', 'tests']: - dest = sorted(set(src + dest)) - result[key] = dest - self.table = dict(result) + value = sorted(set(src + dest)) + else: + value = dest + result[key] = value + self.table = result def update_key(self, dictionary: GLConfig, key: str) -> None: '''Update the given key using value from the given dictionary.''' @@ -297,7 +303,7 @@ class GLConfig: if type(dictionary) is not GLConfig: raise TypeError('dictionary must be a GLConfig, not %s' % type(dictionary).__name__) - dictionary = dict(dictionary.table) + dictionary = dictionary.table self.table[key] = dictionary[key] else: # if key not in self.table raise KeyError('GLConfig does not contain key: %s' % repr(key))