my ($root, $parent_fetcher, $cache) = @_;
$cache ||= {};
- my @STACK; # stack for simulating recursion
+
+ # stacks for simulating recursion
+ my @RSTACK;
+ my @PSTACK;
+ my @MSTACK;
+ my @ISTACK;
my $pfetcher_is_coderef = ref($parent_fetcher) eq 'CODE';
if($seen{$new_root}) {
my @isastack = (
- (map { $_->[0] } @STACK),
+ @RSTACK,
$current_root,
$new_root
);
confess "Could not find method $parent_fetcher in $new_root";
}
- push(@STACK, [
- $current_root,
- $current_parents,
- $recurse_mergeout,
- $i,
- ]);
+ push(@RSTACK, $current_root);
+ push(@PSTACK, $current_parents);
+ push(@MSTACK, $recurse_mergeout);
+ push(@ISTACK, $i);
$current_root = $new_root;
$current_parents = $cache->{pfetch}->{$current_root} ||= [ $current_root->$parent_fetcher ];
\@res;
};
- return @$mergeout if !@STACK;
+ return @$mergeout if !@ISTACK;
- ($current_root, $current_parents, $recurse_mergeout, $i)
- = @{pop @STACK};
+ $current_root = pop(@RSTACK);
+ $current_parents = pop(@PSTACK);
+ $recurse_mergeout = pop(@MSTACK);
+ $i = pop(@ISTACK);
push(@$recurse_mergeout, $mergeout) if @$mergeout;
}