From: Vincent Pit Date: Sat, 28 Jul 2012 17:11:29 +0000 (+0200) Subject: Optimize POD section handling in _parse_fh() X-Git-Tag: release_1.0.10~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FModule-Metadata.git;a=commitdiff_plain;h=921abefc6515ee816ce328eba4ac604e37d89752 Optimize POD section handling in _parse_fh() This is one of the hot spots that NYTProf points out for _parse_fh(). Avoiding the negative lookahead and the redundant regexp match for /^=cut/ yields a 10% speedup. --- diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm index e52a0e2..4fad0f3 100644 --- a/lib/Module/Metadata.pm +++ b/lib/Module/Metadata.pm @@ -456,12 +456,16 @@ sub _parse_fh { chomp( $line ); next if $line =~ /^\s*#/; - $in_pod = ($line =~ /^=(?!cut)/) ? 1 : ($line =~ /^=cut/) ? 0 : $in_pod; + my $is_cut; + if ( $line =~ /^=(.{0,3})/ ) { + $is_cut = $1 eq 'cut'; + $in_pod = !$is_cut; + } # Would be nice if we could also check $in_string or something too last if !$in_pod && $line =~ /^__(?:DATA|END)__$/; - if ( $in_pod || $line =~ /^=cut/ ) { + if ( $in_pod || $is_cut ) { if ( $line =~ /^=head\d\s+(.+)\s*$/ ) { push( @pod, $1 );