Просмотр исходного кода

dpkg-shlibdeps: optimize "dpkg -S" lookups by caching results

Raphael Hertzog лет назад: 18
Родитель
Сommit
0d3c61deb4
3 измененных файлов с 24 добавлено и 2 удалено
  1. 6 0
      ChangeLog
  2. 3 0
      debian/changelog
  3. 15 2
      scripts/dpkg-shlibdeps.pl

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2007-11-23  Raphael Hertzog  <hertzog@debian.org>
+
+	* scripts/dpkg-shlibdeps.pl: Apply patch from Aaron M. Ucko
+	<ucko@debian.org> to optimize "dpkg -S" lookups by caching
+	results.
+
 2007-11-23  Raphael Hertzog  <hertzog@debian.org>
 
 	* scripts/dpkg-shlibdeps.pl: Limit the number of warnings

+ 3 - 0
debian/changelog

@@ -1,11 +1,14 @@
 dpkg (1.14.11) UNRELEASED; urgency=low
 
+  [ Raphael Hertzog ]
   * dpkg-shlibdeps now ignores the lack of dependency information in some
     specific cases (instead of failing):
     - when the library is in the same package than the binary analyzed
     - when the library is not versionned and can't have a shlibs file
   * dpkg-shlibdeps now only displays 10 warnings about symbols not found for
     each binary and a count of skipped warnings. Closes: #452318
+  * dpkg-shlibdeps: optimize "dpkg -S" lookups by caching results, patch
+    from Aaron M. Ucko <ucko@debian.org>. Closes: #452577
 
  -- Guillem Jover <guillem@debian.org>  Fri, 23 Nov 2007 06:50:02 +0200
 

+ 15 - 2
scripts/dpkg-shlibdeps.pl

@@ -518,9 +518,22 @@ sub my_find_library {
     return undef;
 }
 
+my %cached_pkgmatch = ();
+
 sub find_packages {
-    my @files = (@_);
+    my @files;
     my $pkgmatch = {};
+
+    foreach (@_) {
+	if (exists $cached_pkgmatch{$_}) {
+	    $pkgmatch->{$_} = $cached_pkgmatch{$_};
+	} else {
+	    push @files, $_;
+	    $cached_pkgmatch{$_} = [""]; # placeholder to cache misses too.
+	}
+    }
+    return $pkgmatch unless scalar(@files);
+
     my $pid = open(DPKG, "-|");
     syserr(_g("cannot fork for dpkg --search")) unless defined($pid);
     if (!$pid) {
@@ -538,7 +551,7 @@ sub find_packages {
 	    print(STDERR " $_\n")
 		|| syserr(_g("write diversion info to stderr"));
 	} elsif (m/^([^:]+): (\S+)$/) {
-	    $pkgmatch->{$2} = [ split(/, /, $1) ];
+	    $cached_pkgmatch{$2} = $pkgmatch->{$2} = [ split(/, /, $1) ];
 	} else {
 	    warning(_g("unknown output from dpkg --search: '%s'"), $_);
 	}