From 44f0a6762e5465c1a7c09b8f83249d67c04f8dbf Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Sun, 2 Jun 2019 12:50:04 +0200 Subject: [PATCH] Improving speed of matching ~40% --- wani.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wani.py b/wani.py index 65d7600..6b2e03b 100644 --- a/wani.py +++ b/wani.py @@ -468,12 +468,13 @@ def build_morphology_regex(restriction): if typ: min_msd_length = max(index + 1, min_msd_length) + re_objects = [re.compile(r) for r in rgx] def matcher(text): if len(text) <= min_msd_length: return False - for c, r in zip(text, rgx): - if not re.match(r, c): + for c, r in zip(text, re_objects): + if not r.match(c): return False return True