IkiWiki::pagename: memoize results
authorSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Mon, 24 Aug 2009 23:02:27 +0000 (00:02 +0100)
committerSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Mon, 24 Aug 2009 23:31:24 +0000 (00:31 +0100)
This relies for its correctness on %config, %hooks and pagetype() not
changing.

IkiWiki.pm

index 35fee1aa742aab8fbffb405afa82a7f759df6b9e..8a86957684e1b7600b47ed5aee07b79d506e3995 100644 (file)
@@ -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;
 }