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 E8367209BE for ; Wed, 5 Oct 2016 23:57:26 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 09/17] thread: remove iterate_down Date: Wed, 5 Oct 2016 23:57:14 +0000 Message-Id: <20161005235722.14857-10-e@80x24.org> In-Reply-To: <20161005235722.14857-1-e@80x24.org> References: <20161005235722.14857-1-e@80x24.org> List-Id: Unnecessary subs and complexity. This was hiding the fact that $before is never used. --- lib/PublicInbox/SearchThread.pm | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/lib/PublicInbox/SearchThread.pm b/lib/PublicInbox/SearchThread.pm index a161662..dad783e 100644 --- a/lib/PublicInbox/SearchThread.pm +++ b/lib/PublicInbox/SearchThread.pm @@ -81,8 +81,7 @@ sub _add_message ($$) { } sub order { - my $self = shift; - my $ordersub = shift; + my ($self, $ordersub) = @_; # make a fake root my $root = _get_cont_for_id($self, 'fakeroot'); @@ -174,22 +173,6 @@ sub set_children { } while ($walk); } -sub order_children { - my $self = shift; - my $ordersub = shift; - - return unless $ordersub; - - my $sub = sub { - my $cont = shift; - my $children = $cont->children; - return if @$children < 2; - $cont->set_children( $ordersub->( $children ) ); - }; - $self->iterate_down( undef, $sub ); - undef $sub; -} - # non-recursive version of recurse_down to avoid stack depth warnings sub recurse_down { my ($self, $callback) = @_; @@ -216,17 +199,14 @@ sub recurse_down { } } -sub iterate_down { - my $self = shift; - my ($before, $after) = @_; +sub order_children { + my ($walk, $ordersub) = @_; my %seen; - my $walk = $self; my $depth = 0; my @visited; while ($walk) { - push @visited, [ $walk, $depth ]; - $before->($walk, $depth) if $before; + push @visited, $walk; # spot/break loops $seen{$walk}++; @@ -258,8 +238,15 @@ sub iterate_down { } $walk = $next; } - return unless $after; - while (@visited) { $after->(@{ pop @visited }) } + foreach my $cont (@visited) { + my $children = $cont->children; + next if @$children < 2; + $children = $ordersub->($children); + $cont = $cont->{child} = shift @$children; + do { + $cont = $cont->{next} = shift @$children; + } while ($cont); + } } 1; -- EW