[PATCH 3/4] hvsupport: construct regex up front

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This lets perl cache the regex.

Even though there are only eight groups, the speedup is more than that.
---
 docs/hvsupport.pl | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/docs/hvsupport.pl b/docs/hvsupport.pl
index 80a6f80..31821ad 100755
--- a/docs/hvsupport.pl
+++ b/docs/hvsupport.pl
@@ -204,28 +204,27 @@ foreach my $src (@srcs) {
     open FILE, "<$src" or
         die "cannot read $src: $!";
 
+    my $grps = join("|", keys %groups);
     $ingrp = undef;
     my $impl;
     while (defined($line = <FILE>)) {
         if (!$ingrp) {
-            foreach my $grp (keys %groups) {
-                if ($line =~ /^\s*(?:static\s+)?$grp\s+(\w+)\s*=\s*{/ ||
-                    $line =~ /^\s*(?:static\s+)?$grp\s+NAME\(\w+\)\s*=\s*{/) {
-                    $ingrp = $grp;
-                    $impl = $src;
-
-                    if ($impl =~ m,.*/node_device_(\w+)\.c,) {
-                        $impl = $1;
-                    } else {
-                        $impl =~ s,.*/(\w+?)_((\w+)_)?(\w+)\.c,$1,;
-                    }
-
-                    if ($groups{$ingrp}->{drivers}->{$impl}) {
-                        die "Group $ingrp already contains $impl";
-                    }
-
-                    $groups{$ingrp}->{drivers}->{$impl} = {};
+            if ($line =~ /^\s*(?:static\s+)?($grps)\s+(\w+)\s*=\s*{/ ||
+                $line =~ /^\s*(?:static\s+)?($grps)\s+NAME\(\w+\)\s*=\s*{/) {
+                $ingrp = $1;
+                $impl = $src;
+
+                if ($impl =~ m,.*/node_device_(\w+)\.c,) {
+                    $impl = $1;
+                } else {
+                    $impl =~ s,.*/(\w+?)_((\w+)_)?(\w+)\.c,$1,;
                 }
+
+                if ($groups{$ingrp}->{drivers}->{$impl}) {
+                    die "Group $ingrp already contains $impl";
+                }
+
+                $groups{$ingrp}->{drivers}->{$impl} = {};
             }
 
         } else {
-- 
2.7.3

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]