]> Sergey Matveev's repositories - public-inbox.git/commitdiff
imap: simplify partial fetch structure
authorEric Wong <e@yhbt.net>
Wed, 10 Jun 2020 07:04:15 +0000 (07:04 +0000)
committerEric Wong <e@yhbt.net>
Sat, 13 Jun 2020 07:55:45 +0000 (07:55 +0000)
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.

lib/PublicInbox/IMAP.pm

index fffd611b3c6ee5df0b9dce0eaf29231f46e9f2f6..673e164621654a0201ba970af8185b730390412c 100644 (file)
@@ -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) {