optimise single dot detection
authorJoey Hess <joey@kitenet.net>
Mon, 30 Aug 2010 17:36:00 +0000 (13:36 -0400)
committerJoey Hess <joey@kitenet.net>
Mon, 30 Aug 2010 17:36:00 +0000 (13:36 -0400)
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.

IkiWiki.pm

index 6fd11296013eef2004dee6dd939c70230eaaf70c..6da281999f0b4c035805626f11d6e244c105d69f 100644 (file)
@@ -2401,14 +2401,17 @@ package IkiWiki::PageSpec;
 sub derel ($$) {
        my $path=shift;
        my $from=shift;
-       if ($path eq '.') {
-               $path = $from;
-       }
 
-       if ($path =~ m!^\./!) {
-               $from=~s#/?[^/]+$## if defined $from;
-               $path=~s#^\./##;
-               $path="$from/$path" if defined $from && length $from;
+       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;