optimise single dot detection

Since it already looks for things starting with a dot, I was able to avoid
matching against the string twice.

This also fixes a minor bug; $from may not be defined. Avoid uninitialized
value warnings in this case.
master
Joey Hess 2010-08-30 13:36:00 -04:00
parent 7d1cc3a020
commit 991d01f5b5
1 changed files with 10 additions and 7 deletions

View File

@ -2401,15 +2401,18 @@ package IkiWiki::PageSpec;
sub derel ($$) {
my $path=shift;
my $from=shift;
if ($path eq '.') {
$path = $from;
}
if ($path =~ m!^\./!) {
if ($path =~ m!^\.(/|$)!) {
if ($1) {
$from=~s#/?[^/]+$## if defined $from;
$path=~s#^\./##;
$path="$from/$path" if defined $from && length $from;
}
else {
$path = $from;
$path = "" unless defined $path;
}
}
return $path;
}