diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-12-18 17:21:14 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-12-19 13:55:19 +0100 |
commit | 3a527656fd7999878fb0ad4e500f5c44148c5bd2 (patch) | |
tree | dbb49e400e2357f8147c743fd81c34030f4a7a33 | |
parent | 4027e27b35630b1e4213355d1223d476fa09a600 (diff) | |
download | perl-3a527656fd7999878fb0ad4e500f5c44148c5bd2.tar.gz |
In buildtoc, move the "has a NAME?" file check into podset().
Instead of opening each file to search for /^=head1\s+NAME\b/ within the
File::Find::find() callback, move the check to the main processing code in
podset(), where the file is already open. Seeking the file back to the start
is less costly than closing and subsequently reopening, and performing all the
reads at the same time reduces pressure on the OS disk cache.
-rw-r--r-- | pod/buildtoc | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/pod/buildtoc b/pod/buildtoc index c61a425c85..e35dcc412e 100644 --- a/pod/buildtoc +++ b/pod/buildtoc @@ -34,17 +34,7 @@ find(sub { return if $file =~ m!XS/(?:APItest|Typemap)!; my $pod = $_; return if $pod =~ s/pm$/pod/ && -e $pod; - open my $f, '<', $_ or my_die "Can't open file '$_': $!"; - { - my $line; - while ($line = <$f>) { - if ($line =~ /^=head1\s+NAME\b/) { - push @modpods, $file; - return; - } - } - warn "$0: NOTE: cannot find '=head1 NAME' in:\n $file\n" unless $Quiet; - } + push @modpods, $file; } }, 'lib'); @@ -222,10 +212,24 @@ my ($inhead1, $inhead2, $initem); sub podset { my ($pod, $file) = @_; - local $/ = ''; + open my $fh, '<', $file or my_die "Can't open file '$file' for $pod: $!"; + local *_; + my $found_pod; + while (<$fh>) { + if (/^=head1\s+NAME\b/) { + ++$found_pod; + last; + } + } - open my $fh, '<', $file or my_die "Can't open file '$file' for $pod: $!"; + unless ($found_pod) { + warn "$0: NOTE: cannot find '=head1 NAME' in:\n $file\n" unless $Quiet; + return; + } + + seek $fh, 0, 0 or my_die "Can't rewind file '$file': $!"; + local $/ = ''; while(<$fh>) { tr/\015//d; |