projects
/
ikiwiki.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
match_glob: streamline glob cache slightly
[ikiwiki.git]
/
IkiWiki.pm
diff --git
a/IkiWiki.pm
b/IkiWiki.pm
index 08a3d7875da6b9941000b4531755fcb2a6f42d49..57e23fda8c8727d4f5d6d0a9f3022e4e88a77e06 100644
(file)
--- a/
IkiWiki.pm
+++ b/
IkiWiki.pm
@@
-2482,6
+2482,8
@@
sub derel ($$) {
return $path;
}
return $path;
}
+my %glob_cache;
+
sub match_glob ($$;@) {
my $page=shift;
my $glob=shift;
sub match_glob ($$;@) {
my $page=shift;
my $glob=shift;
@@
-2489,8
+2491,13
@@
sub match_glob ($$;@) {
$glob=derel($glob, $params{location});
$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} = qr/^$re$/i;
+ }
+ if ($page=~ $glob_cache{$glob}) {
if (! IkiWiki::isinternal($page) || $params{internal}) {
return IkiWiki::SuccessReason->new("$glob matches $page");
}
if (! IkiWiki::isinternal($page) || $params{internal}) {
return IkiWiki::SuccessReason->new("$glob matches $page");
}