Subject: | [PATCH] Minor optimisation |
See attached patch.
Before:
$ time perl -e 'system "perl -Mblib t/01-basic.t >/dev/null" for 1..10'
real 0m1.425s
user 0m1.122s
sys 0m0.255s
After:
$ time perl -e 'system "perl -Mblib t/01-basic.t >/dev/null" for 1..10'
real 0m1.392s
user 0m1.088s
sys 0m0.256s
The reason this speeds things up is that File::Spec::Unix::canonpath contains a whole list of
substitutions:
$path =~ s|/{2,}|/|g; # xx////xx -> xx/xx
$path =~ s{(?:/\.)+(?:/|\z)}{/}g; # xx/././xx -> xx/xx
$path =~ s|^(?:\./)+||s unless $path eq "./"; # ./xx -> xx
$path =~ s|^/(?:\.\./)+|/|; # /../../xx -> xx
$path =~ s|^/\.\.$|/|; # /.. -> /
$path =~ s|/\z|| unless $path eq "/"; # xx/ -> xx
Any substitution that fails will leave $path as an object, resulting in many calls to ->stringify.
I imagine the same technique could be used for speed elsewhere, but I haven’t checked.
Subject: | open_EGjWwgaR.txt |
diff -rup Path-Class-0.26-TAUTwW/lib/Path/Class/Dir.pm Path-Class-0.26-O4pw7v/lib/Path/Class/Dir.pm
--- Path-Class-0.26-TAUTwW/lib/Path/Class/Dir.pm 2012-06-14 19:53:35.000000000 -0700
+++ Path-Class-0.26-O4pw7v/lib/Path/Class/Dir.pm 2012-11-27 16:16:23.000000000 -0800
@@ -34,7 +34,7 @@ sub new {
shift()
);
- ($self->{volume}, my $dirs) = $s->splitpath( $s->canonpath($first) , 1);
+ ($self->{volume}, my $dirs) = $s->splitpath( $s->canonpath("$first"), 1);
$self->{dirs} = [$s->splitdir($s->catdir($dirs, @_))];
return $self;