Parcourir la source

dpkg-shlibdeps: Do not use readline operator in a foreach loop

These are very slow as the list context forces the operator to read
the entire stream before starting the loop.

Fixes InputOutput::ProhibitReadlineInForLoop.

Warned-by: perlcritic
Guillem Jover il y a 13 ans
Parent
commit
90baddbae2
2 fichiers modifiés avec 3 ajouts et 1 suppressions
  1. 2 1
      scripts/dpkg-shlibdeps.pl
  2. 1 0
      test/100_critic.t

+ 2 - 1
scripts/dpkg-shlibdeps.pl

@@ -454,7 +454,8 @@ if ($stdout) {
     if (-e $varlistfile) {
 	open(my $old_fh, '<', $varlistfile) ||
 	    syserr(_g("open old varlist file \`%s' for reading"), $varlistfile);
-	foreach my $entry (grep { not m/^\Q$varnameprefix\E:/ } (<$old_fh>)) {
+	while (my $entry = <$old_fh>) {
+	    next if $entry =~ m/^\Q$varnameprefix\E:/;
 	    print($new_fh $entry) ||
 	        syserr(_g("copy old entry to new varlist file \`%s'"),
 	               "$varlistfile.new");

+ 1 - 0
test/100_critic.t

@@ -55,6 +55,7 @@ my @policies = qw(
     InputOutput::ProhibitInteractiveTest
     InputOutput::ProhibitJoinedReadline
     InputOutput::ProhibitOneArgSelect
+    InputOutput::ProhibitReadlineInForLoop
     InputOutput::ProhibitTwoArgOpen
     InputOutput::RequireEncodingWithUTF8Layer
     Miscellanea::ProhibitFormats