From 991d01f5b53250b962725110903b0324c93fbfb6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 30 Aug 2010 13:36:00 -0400 Subject: 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. --- IkiWiki.pm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/IkiWiki.pm b/IkiWiki.pm index 6fd112960..6da281999 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -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; -- cgit v1.2.3