]> xenbits.xensource.com Git - libvirt.git/commitdiff
scripts: speedup prohibit-duplicate-header
authorJán Tomko <jtomko@redhat.com>
Wed, 9 Oct 2019 19:02:38 +0000 (21:02 +0200)
committerJán Tomko <jtomko@redhat.com>
Fri, 22 Nov 2019 10:40:52 +0000 (11:40 +0100)
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>
scripts/prohibit-duplicate-header.py

index dfdfa0bf0b6c3d00b8df4e1619036ae3459dd75c..420311ccefc8dc2ea059c93a979b29d5b9373817 100644 (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)