From 5fd1627551b8c77efa5b642483ea4a534811f6c6 Mon Sep 17 00:00:00 2001 From: Andreas Ziegler <andreas.ziegler@fau.de> Date: Fri, 15 Jul 2022 16:05:51 +0200 Subject: [PATCH] library: use compiled pattern in search for functions This speeds up the process as the pattern does not have to be compiled over and over again but is cached. --- librarytrader/library.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/librarytrader/library.py b/librarytrader/library.py index 47fcf0a..73504c7 100644 --- a/librarytrader/library.py +++ b/librarytrader/library.py @@ -1196,9 +1196,9 @@ class Library: def find_local_functions(self, requested_pattern): retval = set() - pattern_string = r'(.*\.c[c]?_|)' + re.escape(requested_pattern) + pattern = re.compile(r'(.*\.c[c]?_|)' + re.escape(requested_pattern)) for addr, names in self.local_functions.items(): - if any(re.fullmatch(pattern_string, name) for name in names): + if any(pattern.fullmatch(name) for name in names): retval.add(addr) return retval @@ -1219,11 +1219,11 @@ class Library: def find_exports_by_pattern(self, requested_pattern): retval = set() - escaped_pattern = re.escape(requested_pattern) + escaped_pattern = re.compile(re.escape(requested_pattern)) for name, addr in self.exported_names.items(): - if re.fullmatch(escaped_pattern, name): + if escaped_pattern.fullmatch(name): retval.add(addr) - elif re.fullmatch(escaped_pattern, name.split('@@')[0]): + elif escaped_pattern.fullmatch(name.split('@@')[0]): retval.add(addr) return retval -- GitLab