summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKathryn Andersen <perlkat@katspace.org>2010-11-14 16:22:15 +0000
committerSimon McVittie <smcv@debian.org>2010-11-19 23:46:46 +0000
commitff0e244701a6ead7f5a0b5826ac39bd42bad55ff (patch)
treee6f763ba68e1844a4904bc6792ccf7e8d6313148
parenta4cb86d73327e7850eeb524ef387b17ac5e1614d (diff)
Improve the speed of match_glob
-rw-r--r--IkiWiki.pm12
1 files changed, 10 insertions, 2 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 08a3d7875..75b7a7b3e 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -2482,6 +2482,8 @@ sub derel ($$) {
return $path;
}
+my %glob_cache;
+
sub match_glob ($$;@) {
my $page=shift;
my $glob=shift;
@@ -2489,8 +2491,14 @@ 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 (!exists $glob_cache{$glob}
+ or !defined $glob_cache{$glob}) {
+ my $re = IkiWiki::glob2re($glob);
+ $glob_cache{$glob} = qr/^$re$/i;
+ }
+ if ($page=~ $glob_cache{$glob}) {
if (! IkiWiki::isinternal($page) || $params{internal}) {
return IkiWiki::SuccessReason->new("$glob matches $page");
}