[PATCH 2/4] hvsupport: drop XML::XPath

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

 



Doing an XPath query for every single 'function' element in the
file is inefficient.

Since the XML file is generated by another of our build scripts
(apibuild.py, using Python's standard 'output.write' XML library),
just find the function name->file mapping by a regex upfront.
---
 bootstrap.conf    |  1 -
 docs/hvsupport.pl | 30 +++++++++++++++++++++++++-----
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 0db6b62..c7263f4 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -208,7 +208,6 @@ gzip       -
 libtool    -
 patch      -
 perl       5.5
-perl::XML::XPath -
 pkg-config -
 rpcgen     -
 tar        -
diff --git a/docs/hvsupport.pl b/docs/hvsupport.pl
index 7a6f1ac..80a6f80 100755
--- a/docs/hvsupport.pl
+++ b/docs/hvsupport.pl
@@ -4,8 +4,6 @@ use strict;
 use warnings;
 
 use File::Find;
-use XML::XPath;
-use XML::XPath::XMLParser;
 
 die "syntax: $0 SRCDIR\n" unless int(@ARGV) == 1;
 
@@ -45,6 +43,29 @@ find({
         }
     }, no_chdir => 1}, $srcdir);
 
+sub parseAPIXML {
+    my $xmlfilename = shift;
+
+    my %files;
+    my $line;
+
+    open FILE, "<", $xmlfilename or die "cannot read $xmlfilename: $!";
+
+    while (defined($line = <FILE>)) {
+        chomp $line;
+        if ($line =~ /function name='([^']+)' file='([^']+)'/) {
+            $files{$1} = $2;
+        }
+    }
+
+    close FILE;
+
+    if (keys %files == 0) {
+        die "No functions found in $xmlfilename. Has the apibuild.py output changed?";
+    }
+    return \%files;
+}
+
 sub parseSymsFile {
     my $apisref = shift;
     my $prefix = shift;
@@ -55,7 +76,7 @@ sub parseSymsFile {
     my $vers;
     my $prevvers;
 
-    my $apixpath = XML::XPath->new(filename => $xmlfilename);
+    my $filenames = parseAPIXML($xmlfilename);
 
     open FILE, "<$filename"
         or die "cannot read $filename: $!";
@@ -83,10 +104,9 @@ sub parseSymsFile {
             $prevvers = $vers;
             $vers = undef;
         } elsif ($line =~ /\s*(\w+)\s*;\s*$/) {
-            my $file = $apixpath->find("/api/symbols/function[\@name='$1']/\@file");
             $$apisref{$1} = {};
             $$apisref{$1}->{vers} = $vers;
-            $$apisref{$1}->{file} = $file;
+            $$apisref{$1}->{file} = $$filenames{$1};
         } else {
             die "unexpected data $line\n";
         }
-- 
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]