summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-10-24 22:27:48 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-10-26 18:22:17 -0700
commitedfed4c3099abba2a8b83e8dde6bcff0952c07f5 (patch)
tree9fa1f8bd181f73863303416ec9d4bc56d64cecf4
parent293dcbbbfd30a0f0282734d71ac98c53abfd07ec (diff)
downloadperl-edfed4c3099abba2a8b83e8dde6bcff0952c07f5.tar.gz
Speed up csh_glob
If it’s not going to be using the pattern at all (due to iteration), there is absolutely no point in parsing it. This will speed up CORE::glob and <...> as well, since they use csh_glob by default.
-rw-r--r--ext/File-Glob/Glob.pm42
1 files changed, 21 insertions, 21 deletions
diff --git a/ext/File-Glob/Glob.pm b/ext/File-Glob/Glob.pm
index c5809c9a08..f9f0eddd2e 100644
--- a/ext/File-Glob/Glob.pm
+++ b/ext/File-Glob/Glob.pm
@@ -77,27 +77,6 @@ my %entries;
sub csh_glob {
my $pat = shift;
my $cxix = shift;
- my @pat;
-
- # glob without args defaults to $_
- $pat = $_ unless defined $pat;
-
- # extract patterns
- $pat =~ s/^\s+//; # Protect against empty elements in
- # things like < *.c>, which alone
- # shouldn't trigger ParseWords. Patterns
- # with a trailing space must be passed
- # to ParseWords, in case it is escaped,
- # as in glob('\ ').
- if ($pat =~ /[\s"']/) {
- # XXX this is needed for compatibility with the csh
- # implementation in Perl. Need to support a flag
- # to disable this behavior.
- require Text::ParseWords;
- for (@pat = Text::ParseWords::parse_line('\s+',1,$pat)) {
- s/^['"]// and chop;
- }
- }
# assume global context if not provided one
$cxix = '_G_' unless defined $cxix;
@@ -105,6 +84,27 @@ sub csh_glob {
# if we're just beginning, do it all first
if ($iter{$cxix} == 0) {
+ my @pat;
+
+ # glob without args defaults to $_
+ $pat = $_ unless defined $pat;
+
+ # extract patterns
+ $pat =~ s/^\s+//; # Protect against empty elements in
+ # things like < *.c>, which alone
+ # shouldn't trigger ParseWords. Patterns
+ # with a trailing space must be passed
+ # to ParseWords, in case it is escaped,
+ # as in glob('\ ').
+ if ($pat =~ /[\s"']/) {
+ # XXX this is needed for compatibility with the csh
+ # implementation in Perl. Need to support a flag
+ # to disable this behavior.
+ require Text::ParseWords;
+ for (@pat = Text::ParseWords::parse_line('\s+',1,$pat)) {
+ s/^['"]// and chop;
+ }
+ }
if (@pat) {
$entries{$cxix} = [ map { doglob($_, $DEFAULT_FLAGS) } @pat ];
}