From e9154caf868123ab2558495e831ffd9e097b6c07 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Mon, 8 Apr 2024 02:58:49 -0700 Subject: [PATCH 6/7] gnulib-tool.py: Use a set instead of list for avoided module checks. * pygnulib/GLModuleSystem.py (GLModuleTable.__init__): Use a set instead of a list for avoided modules. This is used only for membership checks when computing the transitive closure of the given modules, therefore prefer the O(1) average case over O(n). (GLModuleTable.setAvoids): Remove sorted() call. --- ChangeLog | 9 +++++++++ pygnulib/GLModuleSystem.py | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index aaa4d63652..db7b7ca3ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-04-08 Collin Funk + + gnulib-tool.py: Use a set instead of list for avoided module checks. + * pygnulib/GLModuleSystem.py (GLModuleTable.__init__): Use a set instead + of a list for avoided modules. This is used only for membership checks + when computing the transitive closure of the given modules, therefore + prefer the O(1) average case over O(n). + (GLModuleTable.setAvoids): Remove sorted() call. + 2024-04-08 Collin Funk gnulib-tool.py: Simplify file list construction. diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 1532610466..60e9846a66 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -750,11 +750,11 @@ class GLModuleTable: % type(inc_all_direct_tests).__name__) self.inc_all_direct_tests = inc_all_direct_tests self.inc_all_indirect_tests = inc_all_indirect_tests - self.avoids = [] # Avoids + self.avoids = set() # Avoids for avoid in self.config.getAvoids(): module = self.modulesystem.find(avoid) if module: - self.avoids.append(module) + self.avoids.add(module) def __repr__(self) -> str: '''x.__repr__() <==> repr(x)''' @@ -1080,7 +1080,7 @@ class GLModuleTable: for module in modules: if type(module) is not GLModule: raise TypeError('each module must be a GLModule instance') - self.avoids = sorted(set(modules)) + self.avoids = set(modules) def getBaseModules(self) -> list[GLModule]: '''Return list of base modules.''' -- 2.44.0