]> Sergey Matveev's repositories - public-inbox.git/commitdiff
imap: ensure_slices_exist: drop needless map and array
authorEric Wong <e@80x24.org>
Thu, 4 Aug 2022 08:17:01 +0000 (08:17 +0000)
committerEric Wong <e@80x24.org>
Thu, 4 Aug 2022 20:09:35 +0000 (20:09 +0000)
We can reduce ops and temporary objects here by folding the
stringification into the `for' loop and push directly into the
{mailboxlist} array; relying on autovivification to turn it into
a noop for the initial population.

lib/PublicInbox/IMAP.pm

index 9955984b0997e28ba86ce196903f2b6e920d3650..bed633e50789cccb8b1790e29b5d752e6c6ff455 100644 (file)
@@ -354,17 +354,14 @@ sub ensure_slices_exist ($$) {
        my ($imapd, $ibx) = @_;
        my $mb_top = $ibx->{newsgroup} // return;
        my $mailboxes = $imapd->{mailboxes};
-       my @created;
+       my $list = $imapd->{mailboxlist}; # may be undef, just autoviv + noop
        for (my $i = int($ibx->art_max/UID_SLICE); $i >= 0; --$i) {
                my $sub_mailbox = "$mb_top.$i";
                last if exists $mailboxes->{$sub_mailbox};
                $mailboxes->{$sub_mailbox} = $ibx;
                $sub_mailbox =~ s/\Ainbox\./INBOX./i; # more familiar to users
-               push @created, $sub_mailbox;
+               push @$list, qq[* LIST (\\HasNoChildren) "." $sub_mailbox\r\n]
        }
-       return unless @created;
-       my $l = $imapd->{mailboxlist} or return;
-       push @$l, map { qq[* LIST (\\HasNoChildren) "." $_\r\n] } @created;
 }
 
 sub inbox_lookup ($$;$) {