X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearchThread.pm;h=00ae9faccc08b7b16aff259fb9cd54165b485eb2;hb=70209c643bd5b21d369dff684218714f5186993b;hp=507f25baab0e04760b3e55c57f116d6a958246a6;hpb=b28e74c9dc0acad164187f6f584f815df1bc6ec7;p=public-inbox.git diff --git a/lib/PublicInbox/SearchThread.pm b/lib/PublicInbox/SearchThread.pm index 507f25ba..00ae9fac 100644 --- a/lib/PublicInbox/SearchThread.pm +++ b/lib/PublicInbox/SearchThread.pm @@ -38,13 +38,13 @@ sub thread { # TODO: move this to a more appropriate place, breaks tests # if we do it during psgi_cull delete $_->{num}; - - PublicInbox::SearchThread::Msg::cast($_); + bless $_, 'PublicInbox::SearchThread::Msg'; if (exists $id_table{$_->{mid}}) { $_->{children} = []; push @imposters, $_; # we'll deal with them later undef; } else { + $_->{children} = {}; # will become arrayref later $id_table{$_->{mid}} = $_; defined($_->{references}); } @@ -83,15 +83,15 @@ sub thread { } } my $ibx = $ctx->{ibx}; - my $rootset = [ grep { # n.b.: delete prevents cyclic refs + my @rootset = grep { # n.b.: delete prevents cyclic refs !delete($_->{parent}) && $_->visible($ibx) - } values %id_table ]; - $rootset = $ordersub->($rootset); - $_->order_children($ordersub, $ctx) for @$rootset; + } values %id_table; + $ordersub->(\@rootset); + $_->order_children($ordersub, $ctx) for @rootset; # parent imposter messages with reused Message-IDs unshift(@{$id_table{$_->{mid}}->{children}}, $_) for @imposters; - $rootset; + \@rootset; } package PublicInbox::SearchThread::Msg; @@ -108,13 +108,6 @@ sub ghost { }, __PACKAGE__; } -# give a existing smsg the methods of this class -sub cast { - my ($smsg) = @_; - $smsg->{children} = {}; - bless $smsg, __PACKAGE__; -} - sub topmost { my ($self) = @_; my @q = ($self); @@ -172,12 +165,12 @@ sub order_children { my @q = ($cur); my $ibx = $ctx->{ibx}; while (defined($cur = shift @q)) { - my $c = $cur->{children}; # The hashref here... - - $c = [ grep { !$seen{$_}++ && visible($_, $ibx) } values %$c ]; - $c = $ordersub->($c) if scalar @$c > 1; - $cur->{children} = $c; # ...becomes an arrayref - push @q, @$c; + # the {children} hashref here... + my @c = grep { !$seen{$_}++ && visible($_, $ibx) } + values %{delete $cur->{children}}; + $ordersub->(\@c) if scalar(@c) > 1; + $cur->{children} = \@c; # ...becomes an arrayref + push @q, @c; } }