scripts: speedup prohibit-duplicate-header

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 <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Ján Tomko 2019-10-09 21:02:38 +02:00
parent 05d28facb5
commit 424a385c3a

View File

@ -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)