[debhelper-devel] [debhelper] 03/06: Dh_Lib: Make -i/-a to avoid Getopt::Long

Niels Thykier nthykier at moszumanska.debian.org
Mon Apr 10 17:39:29 UTC 2017


This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository debhelper.

commit 91b064a0baea0ef37937bce56e5b080ac5a52595
Author: Niels Thykier <niels at thykier.net>
Date:   Mon Apr 10 15:09:30 2017 +0000

    Dh_Lib: Make -i/-a to avoid Getopt::Long
    
    If we need to use Getopt::Long, we pay a ~0.020s overhead (per
    helper).  When doing dpkg-buildpackage -A/-B builds, dh will
    unconditionally pass -i/-a in those cases making each helper cost a
    bit more.
    
    With this change, we short-cut -i and -a (but not their long variants)
    so Dh_Lib can handle those directly.  This reduces the overhead for
    -A/-B so they are comparable to -b.
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 Debian/Debhelper/Dh_Lib.pm | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index e778b89..690f91c 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -59,6 +59,24 @@ my $prefix="/usr";
 sub init {
 	my %params=@_;
 
+	# Check if we can by-pass the expensive Getopt::Long by optimising for the
+	# common case of "-a" or "-i"
+	if (scalar(@ARGV) == 1 && ($ARGV[0] eq '-a' || $ARGV[0] eq '-i') &&
+		! (defined $ENV{DH_OPTIONS} && length $ENV{DH_OPTIONS}) &&
+		! (defined $ENV{DH_INTERNAL_OPTIONS} && length $ENV{DH_INTERNAL_OPTIONS})) {
+
+		# Single -i or -a as dh does it.
+		if ($ARGV[0] eq '-i') {
+			push(@{$dh{DOPACKAGES}}, getpackages('indep'));
+			$dh{DOINDEP} = 1;
+		} else {
+			push(@{$dh{DOPACKAGES}}, getpackages('arch'));
+			$dh{DOARCH} = 1;
+		}
+		# Clear @ARGV so we do not hit the expensive case below
+		@ARGV = ();
+	}
+
 	# Check to see if an option line starts with a dash,
 	# or DH_OPTIONS is set.
 	# If so, we need to pass this off to the resource intensive 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git




More information about the debhelper-devel mailing list