6ae9ed
From 68a5716a222f4fc8b4d8a1568a6c83cf75b860d7 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <68a5716a222f4fc8b4d8a1568a6c83cf75b860d7@dist-git>
6ae9ed
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
6ae9ed
Date: Tue, 28 Jun 2016 15:16:01 +0200
6ae9ed
Subject: [PATCH] hvsupport: construct the group regex upfront
6ae9ed
MIME-Version: 1.0
6ae9ed
Content-Type: text/plain; charset=UTF-8
6ae9ed
Content-Transfer-Encoding: 8bit
6ae9ed
6ae9ed
The %groups hash contains all the driver types (e.g.
6ae9ed
virHypervisorDriver or virSecretDriver).
6ae9ed
6ae9ed
When searching for all the APIs that are implemented by a driver
6ae9ed
of that specific driver type, we keep iterating over the %groups
6ae9ed
hash on every line we look at, then matching against the driver type.
6ae9ed
6ae9ed
This is inefficient because it prevents perl from caching the regex
6ae9ed
and it executes the regex once for every driver type, even though
6ae9ed
one regex matching excludes all the others, since all the driver types
6ae9ed
are different.
6ae9ed
6ae9ed
Construct the regex containing all the driver types upfront to save
6ae9ed
about 6.4s (~98%) of the script execution time.
6ae9ed
6ae9ed
(cherry picked from commit 6dc1f103471518a7f7e2fefaf8f631eb6f2ca922)
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1286679
6ae9ed
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6ae9ed
---
6ae9ed
 docs/hvsupport.pl | 31 +++++++++++++++----------------
6ae9ed
 1 file changed, 15 insertions(+), 16 deletions(-)
6ae9ed
6ae9ed
diff --git a/docs/hvsupport.pl b/docs/hvsupport.pl
6ae9ed
index 7dd7c3f..fca83ca 100755
6ae9ed
--- a/docs/hvsupport.pl
6ae9ed
+++ b/docs/hvsupport.pl
6ae9ed
@@ -207,28 +207,27 @@ foreach my $src (@srcs) {
6ae9ed
     open FILE, "<$src" or
6ae9ed
         die "cannot read $src: $!";
6ae9ed
 
6ae9ed
+    my $groups_regex = join("|", keys %groups);
6ae9ed
     $ingrp = undef;
6ae9ed
     my $impl;
6ae9ed
     while (defined($line = <FILE>)) {
6ae9ed
         if (!$ingrp) {
6ae9ed
-            foreach my $grp (keys %groups) {
6ae9ed
-                if ($line =~ /^\s*(?:static\s+)?$grp\s+(\w+)\s*=\s*{/ ||
6ae9ed
-                    $line =~ /^\s*(?:static\s+)?$grp\s+NAME\(\w+\)\s*=\s*{/) {
6ae9ed
-                    $ingrp = $grp;
6ae9ed
-                    $impl = $src;
6ae9ed
+            if ($line =~ /^\s*(?:static\s+)?($groups_regex)\s+(\w+)\s*=\s*{/ ||
6ae9ed
+                $line =~ /^\s*(?:static\s+)?($groups_regex)\s+NAME\(\w+\)\s*=\s*{/) {
6ae9ed
+                $ingrp = $1;
6ae9ed
+                $impl = $src;
6ae9ed
 
6ae9ed
-                    if ($impl =~ m,.*/node_device_(\w+)\.c,) {
6ae9ed
-                        $impl = $1;
6ae9ed
-                    } else {
6ae9ed
-                        $impl =~ s,.*/(\w+?)_((\w+)_)?(\w+)\.c,$1,;
6ae9ed
-                    }
6ae9ed
-
6ae9ed
-                    if ($groups{$ingrp}->{drivers}->{$impl}) {
6ae9ed
-                        die "Group $ingrp already contains $impl";
6ae9ed
-                    }
6ae9ed
-
6ae9ed
-                    $groups{$ingrp}->{drivers}->{$impl} = {};
6ae9ed
+                if ($impl =~ m,.*/node_device_(\w+)\.c,) {
6ae9ed
+                    $impl = $1;
6ae9ed
+                } else {
6ae9ed
+                    $impl =~ s,.*/(\w+?)_((\w+)_)?(\w+)\.c,$1,;
6ae9ed
                 }
6ae9ed
+
6ae9ed
+                if ($groups{$ingrp}->{drivers}->{$impl}) {
6ae9ed
+                    die "Group $ingrp already contains $impl";
6ae9ed
+                }
6ae9ed
+
6ae9ed
+                $groups{$ingrp}->{drivers}->{$impl} = {};
6ae9ed
             }
6ae9ed
 
6ae9ed
         } else {
6ae9ed
-- 
6ae9ed
2.9.2
6ae9ed