From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A2FE8209C4 for ; Wed, 5 Oct 2016 23:57:27 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 12/17] thread: inline and remove recurse_down logic Date: Wed, 5 Oct 2016 23:57:17 +0000 Message-Id: <20161005235722.14857-13-e@80x24.org> In-Reply-To: <20161005235722.14857-1-e@80x24.org> References: <20161005235722.14857-1-e@80x24.org> List-Id: 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 | 55 +++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/lib/PublicInbox/SearchThread.pm b/lib/PublicInbox/SearchThread.pm index 2e7b79a..153eef2 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 { -- EW