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