From: Eric Wong <e@80x24.org>
Date: Thu, 4 Aug 2022 08:17:01 +0000 (+0000)
Subject: imap: ensure_slices_exist: drop needless map and array
X-Git-Tag: v1.9.0~49
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=956fa442de1699e078cc7babb7a34af83d143307;p=public-inbox.git

imap: ensure_slices_exist: drop needless map and array

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.
---

diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index 9955984b..bed633e5 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -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 ($$;$) {