Package: debhelper
Version: 9.20150629
Severity: wishlist
Tags: patch
Control: block 793404 by -1

Hi!

debhelper might do some expensive calls to dpkg-architecture to check
if an architecture matches a wildcard. Most of the overhead can be
avoided by directly using the perl module Dpkg::Arch. Although it is
not currently marked as public, the function necessary here should be
considered stable, and I'm marking the module as public and exposing
a subset of its functions with dpkg 1.18.2 (including the one used
here). Also the debarch_is function has been part of Dpkg::Arch since
1.14.8 with the exact same semantics.

Here's a tentative untested patch that tries to do that. I'm not sure
how much of a speed up this would give though.

Thanks,
Guillem
From 77d8bf6fd0a0d4c971a0f1ad636d27d6699d8e53 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guil...@debian.org>
Date: Fri, 24 Jul 2015 06:23:51 +0200
Subject: [PATCH] Dh_Lib: Use Dpkg::Arch::debarch_is insted of calling
 dpkg-architecture

This should give a speed boost, as we avoid having to execute the
script, load and parse the architecture tables, and possibly
initialize the expensive architecture variables (if they are not
already present on the environment) on each check.

Signed-off-by: Guillem Jover <guil...@debian.org>
---
 Debian/Debhelper/Dh_Lib.pm | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 387f90a..756820b 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -9,6 +9,7 @@ use strict;
 use warnings;
 
 use Exporter;
+use Dpkg::Arch qw(debarch_is);
 use vars qw(@ISA @EXPORT %dh);
 @ISA=qw(Exporter);
 @EXPORT=qw(&init &doit &doit_noerror &complex_doit &verbose_print &error
@@ -800,17 +801,10 @@ sub buildos {
 		my @archlist=split(/\s+/,shift);
 	
 		foreach my $a (@archlist) {
-			# Avoid expensive dpkg-architecture call to compare
-			# with a simple architecture name. "linux-any" and
-			# other architecture wildcards are (currently)
-			# always hypenated.
-			if ($a !~ /-/) {
-				return 1 if $arch eq $a;
-			}
-			elsif (exists $knownsame{$arch}{$a}) {
+			if (exists $knownsame{$arch}{$a}) {
 				return 1 if $knownsame{$arch}{$a};
 			}
-			elsif (system("dpkg-architecture", "-a$arch", "-i$a") == 0) {
+			elsif (debarch_is($arch, $a) == 0) {
 				return $knownsame{$arch}{$a}=1;
 			}
 			else {
-- 
2.5.0.rc2.392.g76e840b

Reply via email to