]> Sergey Matveev's repositories - public-inbox.git/commitdiff
thread: inline and remove recurse_down logic
authorEric Wong <e@80x24.org>
Wed, 5 Oct 2016 23:47:27 +0000 (23:47 +0000)
committerEric Wong <e@80x24.org>
Wed, 5 Oct 2016 23:53:34 +0000 (23:53 +0000)
We no longer recurse, and it's too hard to come up with
a new name for a sub we will only use once.

lib/PublicInbox/SearchThread.pm

index 2e7b79a0faaaa0d685b98272983114013a47532b..153eef2b32176412efd85cd3f007d70a1e3d3465 100644 (file)
@@ -145,42 +145,13 @@ sub remove_child {
 }
 
 sub has_descendent {
-       my $self = shift;
-       my $child = shift;
-       die "Assertion failed: $child" unless eval {$child};
-       my $there = 0;
-       $self->recurse_down(sub { $there = 1 if $_[0] == $child });
-
-       return $there;
-}
-
-sub children {
-       my $self = shift;
-       my @children;
-       my $visitor = $self->{child};
-       while ($visitor) {
-               push @children, $visitor;
-               $visitor = $visitor->{next};
-       }
-       \@children;
-}
-
-sub set_children {
-       my ($self, $children) = @_;
-       my $walk = $self->{child} = shift @$children;
-       do {
-               $walk = $walk->{next} = shift @$children;
-       } while ($walk);
-}
-
-# non-recursive version of recurse_down to avoid stack depth warnings
-sub recurse_down {
-       my ($self, $callback) = @_;
+       my ($self, $child) = @_;
        my %seen;
        my @q = ($self);
        while (my $cont = shift @q) {
                $seen{$cont} = 1;
-               $callback->($cont);
+
+               return 1 if $cont == $child;
 
                if (my $next = $cont->{next}) {
                        if ($seen{$next}) {
@@ -197,6 +168,26 @@ sub recurse_down {
                        }
                }
        }
+       0;
+}
+
+sub children {
+       my $self = shift;
+       my @children;
+       my $visitor = $self->{child};
+       while ($visitor) {
+               push @children, $visitor;
+               $visitor = $visitor->{next};
+       }
+       \@children;
+}
+
+sub set_children {
+       my ($self, $children) = @_;
+       my $walk = $self->{child} = shift @$children;
+       do {
+               $walk = $walk->{next} = shift @$children;
+       } while ($walk);
 }
 
 sub order_children {