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
This commit is contained in:
David Pursehouse 2013-04-30 10:57:37 +09:00
parent a8864fba9f
commit 84c4d3c345

View File

@ -188,9 +188,9 @@ class Command(object):
def FindProjects(self, args): def FindProjects(self, args):
result = [] result = []
patterns = [re.compile(r'%s' % a, re.IGNORECASE) for a in args]
for project in self.GetProjects(''): for project in self.GetProjects(''):
for arg in args: for pattern in patterns:
pattern = re.compile(r'%s' % arg, re.IGNORECASE)
if pattern.search(project.name) or pattern.search(project.relpath): if pattern.search(project.name) or pattern.search(project.relpath):
result.append(project) result.append(project)
break break