about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchThread.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-10-05 23:47:27 +0000
committerEric Wong <e@80x24.org>2016-10-05 23:53:34 +0000
commit728d8dbcb920cd19f2fe4d7479d770c540274690 (patch)
tree7cb4bad9b209c90acfef1c0e218dbb11c5deff89 /lib/PublicInbox/SearchThread.pm
parent0412f55abd34d90e4efe0b28217d79fa8319834f (diff)
downloadpublic-inbox-728d8dbcb920cd19f2fe4d7479d770c540274690.tar.gz
We no longer recurse, and it's too hard to come up with
a new name for a sub we will only use once.
Diffstat (limited to 'lib/PublicInbox/SearchThread.pm')
-rw-r--r--lib/PublicInbox/SearchThread.pm55
1 files changed, 23 insertions, 32 deletions
diff --git a/lib/PublicInbox/SearchThread.pm b/lib/PublicInbox/SearchThread.pm
index 2e7b79a0..153eef2b 100644
--- a/lib/PublicInbox/SearchThread.pm
+++ b/lib/PublicInbox/SearchThread.pm
@@ -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 {