]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Optimize module set lookups.
authorBruno Haible <bruno@clisp.org>
Thu, 11 Apr 2024 19:49:45 +0000 (21:49 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 11 Apr 2024 19:49:45 +0000 (21:49 +0200)
* gnulib-tool.py (profiler_args): New variable.
* pygnulib/GLModuleSystem.py (GLModuleTable.transitive_closure): Turn
handledmodules into a set.
(GLModuleTable.transitive_closure_separately): For the 'in' test, use
a set variable main_modules_set.

ChangeLog
gnulib-tool.py
pygnulib/GLModuleSystem.py

index f416f5c8f1c20492036aa6040f1bab99651a4f89..9edb2fac9ca3d8d3c922a050460b4db27c734207 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-04-11  Bruno Haible  <bruno@clisp.org>
+
+       gnulib-tool.py: Optimize module set lookups.
+       * gnulib-tool.py (profiler_args): New variable.
+       * pygnulib/GLModuleSystem.py (GLModuleTable.transitive_closure): Turn
+       handledmodules into a set.
+       (GLModuleTable.transitive_closure_separately): For the 'in' test, use
+       a set variable main_modules_set.
+
 2024-04-11  Collin Funk  <collin.funk1@gmail.com>
 
        gnulib-tool.py: Remove redundant backslashes from regexps.
index bb2837a3d5219c2ec196cf18b157ee586ea3be5d..cdcd316909363500abe156d279cd50add9f03560 100755 (executable)
@@ -144,4 +144,7 @@ else
   func_fatal_error "python3 not found; try setting GNULIB_TOOL_IMPL=sh"
 fi
 
-exec python3 "$gnulib_dir/.gnulib-tool.py" "$@"
+profiler_args=
+# For profiling, cf. <https://docs.python.org/3/library/profile.html>.
+#profiler_args="-m cProfile -s tottime"
+exec python3 $profiler_args "$gnulib_dir/.gnulib-tool.py" "$@"
index 01378259d950b89c529fb665b3d0fa336ecb5895..d258fd903f4664ccade55c2eb518a3ba2d720b1a 100644 (file)
@@ -829,7 +829,7 @@ class GLModuleTable:
         # module on the input list has been processed, it is added to the
         # "handled list", so we can avoid to process it again.
         inc_all_tests = self.inc_all_direct_tests
-        handledmodules = []
+        handledmodules = set()
         inmodules = modules
         outmodules = []
         if self.config['conddeps']:
@@ -910,11 +910,11 @@ class GLModuleTable:
                                         self.addConditional(module, depmodule, True)
                                     else:  # if not conditional
                                         self.addUnconditional(depmodule)
-            handledmodules = sorted(set(handledmodules + inmodules_this_round))
+            handledmodules = handledmodules.union(inmodules_this_round)
             # Remove handledmodules from inmodules.
-            inmodules = [module
-                         for module in inmodules
-                         if module not in handledmodules]
+            inmodules = [ module
+                          for module in inmodules
+                          if module not in handledmodules ]
             inmodules = sorted(set(inmodules))
             inc_all_tests = self.inc_all_indirect_tests
         modules = sorted(set(outmodules))
@@ -950,10 +950,11 @@ class GLModuleTable:
         main_modules = self.transitive_closure(basemodules)
         self.config.setInclTestCategory(TESTS['tests'], saved_inctests)
         # Determine tests-related module list.
+        main_modules_set = set(main_modules)
         tests_modules = \
             [ m
               for m in finalmodules
-              if not (m in main_modules and m.getApplicability() == 'main') ]
+              if not (m in main_modules_set and m.getApplicability() == 'main') ]
         # Note: Since main_modules is (hopefully) a subset of finalmodules, this
         # ought to be the same as
         #   [ m