This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Elide use of `grep`
authorMax Maischein <corion@corion.net>
Thu, 3 Oct 2013 16:48:27 +0000 (18:48 +0200)
committerMax Maischein <corion@corion.net>
Sun, 6 Oct 2013 17:48:09 +0000 (19:48 +0200)
The new approach uses more memory as it reads the whole
11 MB CPAN packages file into memory. Also, it makes
less use of parallel multiprocessing now available on
many machines.

Porting/sync-with-cpan

index a0a26d6..795fe1b 100755 (executable)
@@ -243,9 +243,9 @@ unless ($tarball) {
         } or system wget => $package_url, '-qO', $package_file;
     }
 
         } or system wget => $package_url, '-qO', $package_file;
     }
 
-    my  $new_line = `grep '^$cpan_mod ' $package_file`
+    open my $fh, '<', $package_file;
+    (my $new_line) = grep {/^$cpan_mod/} <$fh> # Yes, this needs a lot of memory
                      or die "Cannot find $cpan_mod on CPAN\n";
                      or die "Cannot find $cpan_mod on CPAN\n";
-    chomp $new_line;
     (undef, $new_version, my $new_path) = split ' ', $new_line;
     if (defined $version) {
         $new_path =~ s/-$new_version\./-$version\./;
     (undef, $new_version, my $new_path) = split ' ', $new_line;
     if (defined $version) {
         $new_path =~ s/-$new_version\./-$version\./;
@@ -476,7 +476,9 @@ my @tests = glob 'porting/*.t';
 chomp @tests;
 my @failed;
 foreach my $t (@tests) {
 chomp @tests;
 my @failed;
 foreach my $t (@tests) {
-    my @not = `./perl -I../lib -I.. $t | grep ^not | grep -v "# TODO"`;
+    my @not = grep {!/# TODO/ }
+              grep { /^not/ }
+              `${exe_dir}perl -I../lib -I.. $t`;
     print @not ? '!' : '.';
     push @failed => $t if @not;
 }
     print @not ? '!' : '.';
     push @failed => $t if @not;
 }