- my ($cur, $child) = @_;
- my %seen;
- my @q = ($cur->{parent} || $cur);
-
- while (defined($cur = shift @q)) {
- return 1 if $cur == $child;
-
- if (!$seen{$cur}++) {
- push @q, values %{$cur->{children}};
- }
+ my ($self, $child) = @_;
+ while ($child) {
+ return 1 if $self == $child;
+ $child = $child->{parent};