This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
optimisation for File::Spec::abs2rel where both args are relative
authorBrendan O'Dea <bod@debian.org>
Thu, 6 Jul 2006 01:02:41 +0000 (11:02 +1000)
committerSteve Peters <steve@fisharerojo.org>
Sat, 8 Jul 2006 18:00:17 +0000 (18:00 +0000)
Message-ID: <20060705150241.GA2244@londo.c47.org>

p4raw-id: //depot/perl@28511

lib/File/Spec/Unix.pm

index 8be7329..fc20200 100644 (file)
@@ -364,7 +364,13 @@ sub abs2rel {
     # Can't relativize across volumes
     return $path unless $path_volume eq $base_volume;
 
-    for ($path, $base) { $_ = $self->rel2abs($_) }
+    if (grep $self->file_name_is_absolute($_), $path, $base) {
+       for ($path, $base) { $_ = $self->rel2abs($_) }
+    }
+    else {
+       # save a couple of cwd()s if both paths are relative
+       for ($path, $base) { $_ = $self->catdir('/', $_) }
+    }
 
     my $path_directories = ($self->splitpath($path, 1))[1];
     my $base_directories = ($self->splitpath($base, 1))[1];