From 5cdc32abd7c91f6164b44b970b7e7715aa7ee641 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Mon, 26 Jan 2026 12:32:15 +0100 Subject: [PATCH] jw.pkg.App: Add lru_cache where possible ResultCache is a home-grown result cache. The @lru_cache decorator, now available in Python 3, accomplishes the same thing, so try to ditch ResultCache for it. Sadly, this doesn't entirely work as of now, because it uses hash() to hash the arguments, which won't work for the two list-type arguments to add_modules_from_project_txt() (buf and visited). Signed-off-by: Jan Lindemann --- src/python/jw/pkg/App.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/python/jw/pkg/App.py b/src/python/jw/pkg/App.py index 4579ebbf..b85bd021 100644 --- a/src/python/jw/pkg/App.py +++ b/src/python/jw/pkg/App.py @@ -4,6 +4,7 @@ # import os, sys, argparse, pwd, re +from functools import lru_cache from .lib.App import App as Base from .lib.log import * @@ -139,7 +140,7 @@ class App(Base): self.__pretty_topdir = self.__format_topdir(self.__topdir, args.topdir_format) self.__topdir_fmt = args.topdir_format if self.__topdir is not None: - self.__top_name = self.__res_cache.run(self.read_value, [self.__topdir + '/make/project.conf', 'build', 'name']) + self.__top_name = self.read_value(self.__topdir + '/make/project.conf', 'build', 'name') if not self.__top_name: self.__top_name = re.sub('-[0-9.-]*$', '', os.path.basename(os.path.realpath(self.__topdir))) @@ -167,6 +168,7 @@ class App(Base): seen_add = seen.add return [x for x in seq if not (x in seen or seen_add(x))] + @lru_cache(maxsize=None) def get_os(self, args = ""): import subprocess for d in [ self.__projs_root + '/jw-pkg/scripts', '/opt/jw-pkg/bin' ]: @@ -198,7 +200,7 @@ class App(Base): if self.__os_cascade is not None: return self.__os_cascade.copy() r = [ 'os', platform.system().lower() ] - os = self.__opt_os if self.__opt_os is not None else self.__res_cache.run(self.get_os, []) + os = self.__opt_os if self.__opt_os is not None else self.get_os() name = re.sub('-.*', '', os) series = os while True: @@ -235,6 +237,7 @@ class App(Base): file.close() return r.rstrip() + @lru_cache(maxsize=None) def read_value(self, path, section, key): def scan_section(f, key): @@ -311,7 +314,7 @@ class App(Base): path = proj_root + '/make/project.conf' #print('path = ', path, 'self.__top_name = ', self.__top_name, 'name = ', name) - return self.__res_cache.run(self.read_value, [path, section, key]) + return self.read_value(path, section, key) def collect_values(self, names, section, key): r = ""