From 424a385c3ab8d0c9359e310364f1ec5cf32fe854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Wed, 9 Oct 2019 21:02:38 +0200 Subject: [PATCH] scripts: speedup prohibit-duplicate-header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Running regular expressions with capture groups is expensive. Bail out early if the line does not start with a '#'. This reduces the runtime of the check by two thirds. Signed-off-by: Ján Tomko Reviewed-by: Daniel Henrique Barboza Reviewed-by: Erik Skultety --- scripts/prohibit-duplicate-header.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/prohibit-duplicate-header.py b/scripts/prohibit-duplicate-header.py index dfdfa0bf0b..420311ccef 100644 --- a/scripts/prohibit-duplicate-header.py +++ b/scripts/prohibit-duplicate-header.py @@ -30,6 +30,10 @@ def check_file(filename): for line in fh: lineno = lineno + 1 + # skip non-matching lines early + if line[0] != '#': + continue + headermatch = re.search(r'''^# *include *[<"]([^>"]*\.h)[">]''', line) if headermatch is not None: inc = headermatch.group(1)