From 84c4d3c345352650fce4dbc2df27c4977f9d969e Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 30 Apr 2013 10:57:37 +0900 Subject: [PATCH] Optimise regex pattern compilation in FindProjects Make a list of compiled patterns once, and then iterate over that per project, instead of compiling the patterns again on every project. Change-Id: I91ec430d3060ec76d5e6b61facf6b13e343c90a7 --- command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command.py b/command.py index 66a9e74d..287f4d30 100644 --- a/command.py +++ b/command.py @@ -188,9 +188,9 @@ class Command(object): def FindProjects(self, args): result = [] + patterns = [re.compile(r'%s' % a, re.IGNORECASE) for a in args] for project in self.GetProjects(''): - for arg in args: - pattern = re.compile(r'%s' % arg, re.IGNORECASE) + for pattern in patterns: if pattern.search(project.name) or pattern.search(project.relpath): result.append(project) break