From efc1cb630b04bf553f246be1b1a4ba548483bdfe Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Fri, 19 Apr 2024 11:32:44 -0700 Subject: [PATCH] gnulib-tool.py: Simplify data structures for dependencies. * pygnulib/GLModuleSystem.py (GLModuleTable.__init__): Use a defaultdict for dependers to remove the base initialization case. (GLModuleTable.addConditional): Use a set to disallow duplicates instead of performing list lookups. --- ChangeLog | 8 ++++++++ pygnulib/GLModuleSystem.py | 8 +++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e84856cc05..d907a52c53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-04-19 Collin Funk + + gnulib-tool.py: Simplify data structures for dependencies. + * pygnulib/GLModuleSystem.py (GLModuleTable.__init__): Use a defaultdict + for dependers to remove the base initialization case. + (GLModuleTable.addConditional): Use a set to disallow duplicates instead + of performing list lookups. + 2024-04-19 Bruno Haible gnulib-tool.py: Simplify running some commands in a given directory. diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 112a6bc0e6..ce1fad110c 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -23,6 +23,7 @@ import re import sys import hashlib import subprocess as sp +from collections import defaultdict from . import constants from .GLError import GLError from .GLConfig import GLConfig @@ -721,7 +722,7 @@ class GLModuleTable: returns the condition when B should be enabled as a dependency of A, once the m4 code for A has been executed. ''' - self.dependers = dict() + self.dependers = defaultdict(set) self.conditionals = dict() self.unconditionals = set() self.base_modules = [] @@ -763,10 +764,7 @@ class GLModuleTable: % type(condition).__name__) if str(module) not in self.unconditionals: # No unconditional dependency to the given module is known at this point. - if str(module) not in self.dependers: - self.dependers[str(module)] = [] - if str(parent) not in self.dependers[str(module)]: - self.dependers[str(module)].append(str(parent)) + self.dependers[str(module)].add(str(parent)) key = '%s---%s' % (str(parent), str(module)) self.conditionals[key] = condition -- 2.39.5