add_depends: optimise influence calculation

I made match_* functions whose influences can vary depending on the page
matched set a special "" influence to indicate this.

Then add_depends can try just one page, and if static influences are found,
stop there.
master
Joey Hess 2009-10-09 17:15:40 -04:00
parent ecbe5576f8
commit 74409f940d
3 changed files with 30 additions and 30 deletions

View File

@ -1780,19 +1780,17 @@ sub add_depends ($$;$) {
return 1; return 1;
} }
# Analyse the pagespec, and match it against all pages # Add explicit dependencies for influences.
# to get a list of influences, and add explicit dependencies my $sub=pagespec_translate($pagespec);
# for those. return if $@;
#my $sub=pagespec_translate($pagespec); foreach my $p (keys %pagesources) {
#return if $@; my $r=$sub->($p, location => $page);
#foreach my $p (keys %pagesources) { my $i=$r->influences;
# my $r=$sub->($p, location => $page ); foreach my $k (keys %$i) {
# my %i=$r->influences; $depends_simple{$page}{lc $k} |= $i->{$k};
# foreach my $i (keys %i) { }
# $depends_simple{$page}{lc $i} |= $i{$i}; last if $r->influences_static;
# } }
#}
print STDERR "warning: use of add_depends by ".caller()."; influences not tracked\n";
$depends{$page}{$pagespec} |= $deptype; $depends{$page}{$pagespec} |= $deptype;
return 1; return 1;
@ -2045,9 +2043,9 @@ sub pagespec_match_list ($$;@) {
} }
# Add simple dependencies for accumulated influences. # Add simple dependencies for accumulated influences.
my %i=$accum->influences; my $i=$accum->influences;
foreach my $i (keys %i) { foreach my $k (keys %$i) {
$depends_simple{$page}{lc $i} |= $i{$i}; $depends_simple{$page}{lc $k} |= $i->{$k};
} }
return @matches; return @matches;
@ -2099,12 +2097,14 @@ sub new {
sub influences { sub influences {
my $this=shift; my $this=shift;
if (! @_) { $this->[1]={@_} if @_;
return %{$this->[1]}; my %i=%{$this->[1]};
} delete $i{""};
else { return \%i;
$this->[1]={@_}; }
}
sub influences_static {
return ! $_[0][1]->{""};
} }
sub merge_influences { sub merge_influences {
@ -2173,19 +2173,19 @@ sub match_link ($$;@) {
my $bestlink = IkiWiki::bestlink($from, $link); my $bestlink = IkiWiki::bestlink($from, $link);
foreach my $p (@{$links}) { foreach my $p (@{$links}) {
if (length $bestlink) { if (length $bestlink) {
return IkiWiki::SuccessReason->new("$page links to $link", $page => $IkiWiki::DEPEND_LINKS) return IkiWiki::SuccessReason->new("$page links to $link", $page => $IkiWiki::DEPEND_LINKS, "" => 1)
if $bestlink eq IkiWiki::bestlink($page, $p); if $bestlink eq IkiWiki::bestlink($page, $p);
} }
else { else {
return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page => $IkiWiki::DEPEND_LINKS) return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page => $IkiWiki::DEPEND_LINKS, "" => 1)
if match_glob($p, $link, %params); if match_glob($p, $link, %params);
my ($p_rel)=$p=~/^\/?(.*)/; my ($p_rel)=$p=~/^\/?(.*)/;
$link=~s/^\///; $link=~s/^\///;
return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page => $IkiWiki::DEPEND_LINKS) return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page => $IkiWiki::DEPEND_LINKS, "" => 1)
if match_glob($p_rel, $link, %params); if match_glob($p_rel, $link, %params);
} }
} }
return IkiWiki::FailReason->new("$page does not link to $link"); return IkiWiki::FailReason->new("$page does not link to $link", "" => 1);
} }
sub match_backlink ($$;@) { sub match_backlink ($$;@) {

View File

@ -291,14 +291,14 @@ sub match {
if (defined $val) { if (defined $val) {
if ($val=~/^$re$/i) { if ($val=~/^$re$/i) {
return IkiWiki::SuccessReason->new("$re matches $field of $page", $page => $IkiWiki::DEPEND_CONTENT); return IkiWiki::SuccessReason->new("$re matches $field of $page", $page => $IkiWiki::DEPEND_CONTENT, "" => 1);
} }
else { else {
return IkiWiki::FailReason->new("$re does not match $field of $page"); return IkiWiki::FailReason->new("$re does not match $field of $page", "" => 1);
} }
} }
else { else {
return IkiWiki::FailReason->new("$page does not have a $field"); return IkiWiki::FailReason->new("$page does not have a $field", "" => 1);
} }
} }

View File

@ -632,7 +632,7 @@ in the wiki that match the [[ikiwiki/PageSpec]].
The page will automatically be made to depend on the specified The page will automatically be made to depend on the specified
[[ikiwiki/PageSpec]], so `add_depends` does not need to be called. This [[ikiwiki/PageSpec]], so `add_depends` does not need to be called. This
is significantly more efficient than calling `add_depends` and is often significantly more efficient than calling `add_depends` and
`pagespec_match` in a loop. You should use this anytime a plugin `pagespec_match` in a loop. You should use this anytime a plugin
needs to match a set of pages and do something based on that list. needs to match a set of pages and do something based on that list.