From: Brandon L Black Date: Fri, 10 Nov 2006 00:14:00 +0000 (+0000) Subject: this might be cleaner and faster (inf loop stuff) X-Git-Tag: 0.06~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bb0280c594183a9369798a8fdd3dd477aabf7c63;p=gitmo%2FAlgorithm-C3.git this might be cleaner and faster (inf loop stuff) --- diff --git a/lib/Algorithm/C3.pm b/lib/Algorithm/C3.pm index 5d4ceb3..5e65d3a 100644 --- a/lib/Algorithm/C3.pm +++ b/lib/Algorithm/C3.pm @@ -29,7 +29,8 @@ sub merge { while(1) { if($i < @$current_parents) { my $new_root = $current_parents->[$i++]; - die "Infinite loop detected" if $seen{$new_root}++; + die "Infinite loop detected" if $seen{$new_root}; + $seen{$new_root} = 1; unless ($pfetcher_is_coderef or $new_root->can($parent_fetcher)) { confess "Could not find method $parent_fetcher in $new_root"; @@ -49,6 +50,8 @@ sub merge { next; } + $seen{$current_root} = 0; + my $mergeout = $cache->{merge}->{$current_root} ||= do { # This do-block is the code formerly known as the function @@ -93,8 +96,6 @@ sub merge { return @$mergeout if !@STACK; - $seen{$current_root}--; - ($current_root, $current_parents, $recurse_mergeout, $i) = @{pop @STACK};