]> sipb.mit.edu Git - ikiwiki.git/commitdiff
Use a hash to de-duplicate dependencies
authorSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Mon, 24 Aug 2009 22:01:42 +0000 (23:01 +0100)
committerSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Mon, 24 Aug 2009 23:31:16 +0000 (00:31 +0100)
IkiWiki.pm
IkiWiki/Render.pm
ikiwiki-transition
t/index.t

index 734b167cf8b00287a62f33d95122823e7b3d01a6..21a74adceeb9ee87ab6d072cf5f17608d782032c 100644 (file)
@@ -1508,10 +1508,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,7 +1559,7 @@ sub saveindex () {
                };
 
                if (exists $depends{$page}) {
-                       $index{page}{$src}{dependslist} = $depends{$page};
+                       $index{page}{$src}{dependslist} = [ keys %{$depends{$page}} ];
                }
 
                if (exists $pagestate{$page}) {
@@ -1730,16 +1732,7 @@ sub add_depends ($$) {
 
        return unless pagespec_valid($pagespec);
 
-       if (! exists $depends{$page}) {
-               $depends{$page}=[$pagespec];
-       }
-       else {
-               foreach my $p (@{$depends{$page}}) {
-                       return 1 if $p eq $pagespec;
-               }
-               push @{$depends{$page}}, $pagespec;
-       }
-
+       $depends{$page}{$pagespec} = 1;
        return 1;
 }
 
index 08d484847a5eef33235d33cfdc0d7a39fc5cfbbe..b9f1d7754171004b32cc196230a530e12236b36e 100644 (file)
@@ -459,7 +459,7 @@ sub refresh () {
                        next if $rendered{$f};
                        my $p=pagename($f);
                        if (exists $depends{$p}) {
-                               foreach my $d (@{$depends{$p}}) {
+                               foreach my $d (keys %{$depends{$p}}) {
                                        # only consider internal files
                                        # if the page explicitly depends on such files
                                        foreach my $file (@changed, $d=~/internal\(/ ? @internal : ()) {
index 60cea3d54895f531fce1864d5e21224aa1a3e732..795ab31cb046f8c3c7c579d6b2606432f8a3115c 100755 (executable)
@@ -299,7 +299,7 @@ sub oldloadindex {
                        $pagemtime{$page}=$items{mtime}[0];
                        $oldlinks{$page}=[@{$items{link}}];
                        $links{$page}=[@{$items{link}}];
-                       $depends{$page}=[$items{depends}[0]] if exists $items{depends};
+                       $depends{$page}={ $items{depends}[0] => 1 } if exists $items{depends};
                        $destsources{$_}=$page foreach @{$items{dest}};
                        $renderedfiles{$page}=[@{$items{dest}}];
                        $pagecase{lc $page}=$page;
index 107dac9d0522e73d435738d692af1e7a17cfb358..2f23524a7cc987cf82329a2035370840d36ee3ef 100755 (executable)
--- a/t/index.t
+++ b/t/index.t
@@ -32,9 +32,9 @@ $renderedfiles{"bar.png"}=["bar.png"];
 $links{"Foo"}=["bar.png"];
 $links{"bar"}=["Foo", "new-page"];
 $links{"bar.png"}=[];
-$depends{"Foo"}=[];
-$depends{"bar"}=["foo*"];
-$depends{"bar.png"}=[];
+$depends{"Foo"}={};
+$depends{"bar"}={"foo*" => 1};
+$depends{"bar.png"}={};
 $pagestate{"bar"}{meta}{title}="a page about bar";
 $pagestate{"bar"}{meta}{moo}="mooooo";
 # only loaded plugins save state, so this should not be saved out
@@ -80,9 +80,9 @@ is_deeply(\%links, {
        "bar.png" => [],
 }, "%links loaded correctly");
 is_deeply(\%depends, {
-       Foo => [],
-       bar => ["foo*"],
-       "bar.png" => [],
+       Foo => {},
+       bar => {"foo*" => 1},
+       "bar.png" => {},
 }, "%depends loaded correctly");
 is_deeply(\%pagestate, {
        bar => {