Explorar el Código

Dpkg::Vendor: Cache vendor info Control::Hash objects

Avoid parsing again the current vendor file on each hook invocation,
by caching the parsed object into a hash.
Guillem Jover hace 12 años
padre
commit
82d38b898e
Se han modificado 2 ficheros con 6 adiciones y 0 borrados
  1. 2 0
      debian/changelog
  2. 4 0
      scripts/Dpkg/Vendor.pm

+ 2 - 0
debian/changelog

@@ -38,6 +38,8 @@ dpkg (1.17.7) UNRELEASED; urgency=low
     source control file to fill the «profile» value.
     source control file to fill the «profile» value.
   * Do not interpret the .dsc filename as a regex when recomputing the
   * Do not interpret the .dsc filename as a regex when recomputing the
     md5sum for the .changes file after signing the .dsc. Closes: #742535
     md5sum for the .changes file after signing the .dsc. Closes: #742535
+  * Cache vendor info Control::Hash objects in Dpkg::Vendor::get_vendor_info()
+    when parsing the vendor file on each hook invocation.
 
 
   [ Updated dpkg translations ]
   [ Updated dpkg translations ]
   * German (Sven Joachim).
   * German (Sven Joachim).

+ 4 - 0
scripts/Dpkg/Vendor.pm

@@ -81,12 +81,16 @@ if there's no file for the given vendor.
 
 
 =cut
 =cut
 
 
+my %VENDOR_CACHE;
 sub get_vendor_info(;$) {
 sub get_vendor_info(;$) {
     my $vendor = shift || 'default';
     my $vendor = shift || 'default';
+    return $VENDOR_CACHE{$vendor} if exists $VENDOR_CACHE{$vendor};
+
     my $file = get_vendor_file($vendor);
     my $file = get_vendor_file($vendor);
     return unless $file;
     return unless $file;
     my $fields = Dpkg::Control::HashCore->new();
     my $fields = Dpkg::Control::HashCore->new();
     $fields->load($file) or error(_g('%s is empty'), $file);
     $fields->load($file) or error(_g('%s is empty'), $file);
+    $VENDOR_CACHE{$vendor} = $fields;
     return $fields;
     return $fields;
 }
 }