From: Simon McVittie Date: Mon, 24 Aug 2009 23:02:27 +0000 (+0100) Subject: IkiWiki::pagename: memoize results X-Git-Tag: 3.1415926~65^2~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=275dd5c4ea748261741236a62ad763c775a651c5;p=ikiwiki.git IkiWiki::pagename: memoize results This relies for its correctness on %config, %hooks and pagetype() not changing. --- diff --git a/IkiWiki.pm b/IkiWiki.pm index 35fee1aa7..8a8695768 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -661,9 +661,15 @@ sub pagetype ($) { return; } +my %pagename_cache; + sub pagename ($) { my $file=shift; + if (exists $pagename_cache{$file}) { + return $pagename_cache{$file}; + } + my $type=pagetype($file); my $page=$file; $page=~s/\Q.$type\E*$// @@ -672,6 +678,8 @@ sub pagename ($) { if ($config{indexpages} && $page=~/(.*)\/index$/) { $page=$1; } + + $pagename_cache{$file} = $page; return $page; }