From 2975d18c7233ef2a816f5a480b9065f851489cf3 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Thu, 6 Jul 2017 13:13:39 +0200 Subject: Compile regex outside of for loop --- alot/addressbook/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'alot/addressbook') diff --git a/alot/addressbook/__init__.py b/alot/addressbook/__init__.py index fbd95a99..f30c7274 100644 --- a/alot/addressbook/__init__.py +++ b/alot/addressbook/__init__.py @@ -34,9 +34,8 @@ class AddressBook(object): def lookup(self, query=''): """looks up all contacts where name or address match query""" res = [] - query = '.*%s.*' % query + query = re.compile('.*%s.*' % query, self.reflags) for name, email in self.get_contacts(): - if re.match(query, name, self.reflags) or \ - re.match(query, email, self.reflags): + if query.match(name) or query.match(email): res.append((name, email)) return res -- cgit v1.2.3