diff options
author | Joey Hess <joey@kitenet.net> | 2010-11-20 12:24:00 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-11-20 12:24:00 -0400 |
commit | cfbfbdc5979abc941b08862bd1f66bc986e9ac08 (patch) | |
tree | 7be9d790c50769d12130e4a34a97bc4845e732e6 /IkiWiki.pm | |
parent | c9b737cc8596f9421ba968e56839eb052e80e794 (diff) | |
parent | 55515050e1f3aad13dc96796a347cefa98e8e472 (diff) | |
download | ikiwiki-cfbfbdc5979abc941b08862bd1f66bc986e9ac08.tar ikiwiki-cfbfbdc5979abc941b08862bd1f66bc986e9ac08.tar.gz |
Merge remote branch 'smcv/ready/glob-cache'
Diffstat (limited to 'IkiWiki.pm')
-rw-r--r-- | IkiWiki.pm | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm index 08a3d7875..e5370f4a6 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -2388,7 +2388,7 @@ sub glob2re ($) { my $re=quotemeta(shift); $re=~s/\\\*/.*/g; $re=~s/\\\?/./g; - return $re; + return qr/^$re$/i; } package IkiWiki::FailReason; @@ -2482,6 +2482,8 @@ sub derel ($$) { return $path; } +my %glob_cache; + sub match_glob ($$;@) { my $page=shift; my $glob=shift; @@ -2489,8 +2491,13 @@ sub match_glob ($$;@) { $glob=derel($glob, $params{location}); - my $regexp=IkiWiki::glob2re($glob); - if ($page=~/^$regexp$/i) { + # Instead of converting the glob to a regex every time, + # cache the compiled regex to save time. + if (!defined $glob_cache{$glob}) { + my $re = IkiWiki::glob2re($glob); + $glob_cache{$glob} = $re; + } + if ($page=~ $glob_cache{$glob}) { if (! IkiWiki::isinternal($page) || $params{internal}) { return IkiWiki::SuccessReason->new("$glob matches $page"); } @@ -2660,7 +2667,7 @@ sub match_user ($$;@) { return IkiWiki::ErrorReason->new("no user specified"); } - if (defined $params{user} && $params{user}=~/^$regexp$/i) { + if (defined $params{user} && $params{user}=~$regexp) { return IkiWiki::SuccessReason->new("user is $user"); } elsif (! defined $params{user}) { |