about summary refs log tree commit homepage
path: root/lib/PublicInbox/IMAP.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-06-10 07:04:15 +0000
committerEric Wong <e@yhbt.net>2020-06-13 07:55:45 +0000
commit3601eee7e9370ea6c84052459c6dc4a97efd3e37 (patch)
tree72827384b2e58507b69d59d6f7e048cb5c83b378 /lib/PublicInbox/IMAP.pm
parent40ee12e172f44a2e8eed8654f5e7835ce69a894f (diff)
downloadpublic-inbox-3601eee7e9370ea6c84052459c6dc4a97efd3e37.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/IMAP.pm')
-rw-r--r--lib/PublicInbox/IMAP.pm13
1 files changed, 10 insertions, 3 deletions
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) {