]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Optimize.
authorBruno Haible <bruno@clisp.org>
Fri, 12 Apr 2024 22:10:44 +0000 (00:10 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 12 Apr 2024 22:10:44 +0000 (00:10 +0200)
* pygnulib/GLConfig.py (GLConfig.update, GLConfig.update_key): Avoid
useless cloning of dictionaries.

ChangeLog
pygnulib/GLConfig.py

index b25819a4aa98d7ec13de386bb5c5caa7db00ba41..212a78b3052c2a10690eb1b07d7bb6c62ca8b9d7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-04-12  Bruno Haible  <bruno@clisp.org>
+
+       gnulib-tool.py: Optimize.
+       * pygnulib/GLConfig.py (GLConfig.update, GLConfig.update_key): Avoid
+       useless cloning of dictionaries.
+
 2024-04-12  Bruno Haible  <bruno@clisp.org>
 
        gnulib-tool.py: Implement --no-conditional-dependencies correctly.
index e938b30a5e6f72653ae9762e0c4453985cbd9ce4..515047d3f08f1329fc4c9064c37116b1c351204a 100644 (file)
@@ -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))