[libvirt] [PATCH 1/3] scripts: speedup prohibit-duplicate-header

Ján Tomko posted 3 patches 6 years, 2 months ago
[libvirt] [PATCH 1/3] scripts: speedup prohibit-duplicate-header
Posted by Ján Tomko 6 years, 2 months ago
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>
---
 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)
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/3] scripts: speedup prohibit-duplicate-header
Posted by Erik Skultety 6 years, 2 months ago
On Wed, Nov 20, 2019 at 07:32:44PM +0100, Ján Tomko wrote:
> 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: Erik Skultety <eskultet@redhat.com>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list