The use of array-returning built-ins such as `grep' inside
arrayref declarations appears to result in permanently allocated
scratchpad space for caching according to my malloc inspector.
Thread skeletons get discarded every response, but multiple
skeletons can exist in memory at once, so do what we can to
prevent long-lived allocations from being made, here.
In other words, replacing constructs such as:
my $foo = [ grep(...) ];
with:
my @foo = grep(...);
Seems to ensure the mortality of the underlying array.
}
}
my $ibx = $ctx->{ibx};
}
}
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)
!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;
# parent imposter messages with reused Message-IDs
unshift(@{$id_table{$_->{mid}}->{children}}, $_) for @imposters;
}
package PublicInbox::SearchThread::Msg;
}
package PublicInbox::SearchThread::Msg;
my @q = ($cur);
my $ibx = $ctx->{ibx};
while (defined($cur = shift @q)) {
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 %{$cur->{children}};
+ $ordersub->(\@c) if scalar(@c) > 1;
+ $cur->{children} = \@c; # ...becomes an arrayref
+ push @q, @c;
(eval { $b->topmost->{pct} } // 0) <=>
(eval { $a->topmost->{pct} } // 0)
(eval { $b->topmost->{pct} } // 0) <=>
(eval { $a->topmost->{pct} } // 0)
(eval { $a->topmost->{ds} } || 0) <=>
(eval { $b->topmost->{ds} } || 0)
(eval { $a->topmost->{ds} } || 0) <=>
(eval { $b->topmost->{ds} } || 0)
}
# accumulate recent topics if search is supported
}
# accumulate recent topics if search is supported
eval 'package EmptyInbox; sub smsg_by_mid { undef }';
my $ctx = { ibx => bless {}, 'EmptyInbox' };
my $rootset = PublicInbox::SearchThread::thread($smsgs, sub {
eval 'package EmptyInbox; sub smsg_by_mid { undef }';
my $ctx = { ibx => bless {}, 'EmptyInbox' };
my $rootset = PublicInbox::SearchThread::thread($smsgs, sub {
- [ sort { $a->{mid} cmp $b->{mid} } @{$_[0]} ] }, $ctx);
+ @{$_[0]} = sort { $a->{mid} cmp $b->{mid} } @{$_[0]} }, $ctx);
my $oldout = select $fh;
find_cycle($rootset);
select $oldout;
my $oldout = select $fh;
find_cycle($rootset);
select $oldout;
sub thread_to_s {
my ($msgs) = @_;
my $rootset = PublicInbox::SearchThread::thread($msgs, sub {
sub thread_to_s {
my ($msgs) = @_;
my $rootset = PublicInbox::SearchThread::thread($msgs, sub {
- [ sort { $a->{mid} cmp $b->{mid} } @{$_[0]} ] });
+ @{$_[0]} = sort { $a->{mid} cmp $b->{mid} } @{$_[0]} });
my $st = '';
my @q = map { (0, $_) } @$rootset;
while (@q) {
my $st = '';
my @q = map { (0, $_) } @$rootset;
while (@q) {