projects
/
ikiwiki.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a4cb86d
)
Improve the speed of match_glob
author
Kathryn Andersen
<perlkat@katspace.org>
Sun, 14 Nov 2010 16:22:15 +0000
(16:22 +0000)
committer
Simon McVittie
<smcv@debian.org>
Fri, 19 Nov 2010 23:46:46 +0000
(23:46 +0000)
IkiWiki.pm
patch
|
blob
|
history
diff --git
a/IkiWiki.pm
b/IkiWiki.pm
index 08a3d7875da6b9941000b4531755fcb2a6f42d49..75b7a7b3e116e84e7708a73845cef01a02b02aa4 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,14
@@
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 (!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");
}
if (! IkiWiki::isinternal($page) || $params{internal}) {
return IkiWiki::SuccessReason->new("$glob matches $page");
}