]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki.pm
IkiWiki::pagename: memoize results
[git.ikiwiki.info.git] / IkiWiki.pm
index 3e94c8a257ce2670089916942c2a542a27fd37a3..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;
 }
 
@@ -1508,10 +1516,12 @@ sub loadindex () {
                                $oldlinks{$page}=[@{$d->{links}}];
                        }
                        if (exists $d->{dependslist}) {
-                               $depends{$page}=$d->{dependslist};
+                               $depends{$page}={
+                                       map { $_ => 1 } @{$d->{dependslist}}
+                               };
                        }
                        elsif (exists $d->{depends}) {
-                               $depends{$page}=[$d->{depends}];
+                               $depends{$page}={$d->{depends} => 1};
                        }
                        if (exists $d->{state}) {
                                $pagestate{$page}=$d->{state};
@@ -1557,8 +1567,7 @@ sub saveindex () {
                };
 
                if (exists $depends{$page}) {
-                       $index{page}{$src}{depends} = join(" or ", @{$depends{$page}});
-                       $index{page}{$src}{dependslist} = $depends{$page};
+                       $index{page}{$src}{dependslist} = [ keys %{$depends{$page}} ];
                }
 
                if (exists $pagestate{$page}) {
@@ -1729,18 +1738,18 @@ sub add_depends ($$) {
        my $page=shift;
        my $pagespec=shift;
 
-       return unless pagespec_valid($pagespec);
-
-       if (! exists $depends{$page}) {
-               $depends{$page}=[$pagespec];
-       }
-       else {
-               foreach my $p (@{$depends{$page}}) {
-                       return 1 if $p eq $pagespec;
+       if (ref $pagespec eq 'ARRAY') {
+               foreach my $ps (@$pagespec) {
+                       if (pagespec_valid($ps)) {
+                               $depends{$page}{$ps} = 1;
+                       }
                }
-               push @{$depends{$page}}, $pagespec;
+               return;
        }
 
+       return unless pagespec_valid($pagespec);
+
+       $depends{$page}{$pagespec} = 1;
        return 1;
 }