From: Eric Wong Date: Wed, 10 Jun 2020 07:04:15 +0000 (+0000) Subject: imap: simplify partial fetch structure X-Git-Tag: v1.6.0~449 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=3601eee7e9370ea6c84052459c6dc4a97efd3e37 imap: simplify partial fetch structure While the contents of normal %want hash keys are bounded in size, %partial can cause more overhead and lead to repeated sort calls on multi-message fetches. So sort it once and use arrayrefs to make the data structure more compact. --- diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index fffd611b..673e1646 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -569,8 +569,8 @@ sub partial_prepare ($$$) { sub partial_emit ($$$) { my ($self, $partial, $eml) = @_; - for my $k (sort keys %$partial) { - my ($cb, @args) = @{$partial->{$k}}; + for (@$partial) { + my ($k, $cb, @args) = @$_; my ($offset, $len) = splice(@args, -2); # $cb is partial_body|partial_hdr_get|partial_hdr_not my $str = $cb->($eml, @args) // ''; @@ -607,7 +607,14 @@ sub cmd_uid_fetch ($$$;@) { return "$tag BAD param: $att\r\n"; } } - $want{-partial} = \%partial if scalar keys %partial; + + # stabilize partial order for consistency and ease-of-debugging: + if (scalar keys %partial) { + $want{-partial} = [ map { + [ $_, @{$partial{$_}} ] + } sort keys %partial ]; + } + my ($beg, $end); my $msgs = []; if ($range =~ /\A([0-9]+):([0-9]+)\z/s) {