]> Sergey Matveev's repositories - public-inbox.git/commitdiff
nntp: smsg_range_i: favor ->{$field} lookups when possible
authorEric Wong <e@yhbt.net>
Mon, 1 Jun 2020 10:06:53 +0000 (10:06 +0000)
committerEric Wong <e@yhbt.net>
Wed, 3 Jun 2020 04:04:21 +0000 (04:04 +0000)
PublicInbox::Smsg::date remains the only exception which
requires any subroutine calls, here, so we'll just have
a branch just for that.

lib/PublicInbox/NNTP.pm

index 54207500dd8db5576658ae993169efd10318fdc5..a37910d173966bc3b31307077b08101e8e7e9fab 100644 (file)
@@ -722,8 +722,16 @@ sub smsg_range_i {
        my $msgs = $over->query_xover($$beg, $end);
        scalar(@$msgs) or return;
        my $tmp = '';
-       foreach my $s (@$msgs) {
-               $tmp .= $s->{num} . ' ' . $s->$field . "\r\n";
+
+       # ->{$field} is faster than ->$field invocations, so favor that.
+       if ($field eq 'date') {
+               for my $s (@$msgs) {
+                       $tmp .= "$s->{num} ".PublicInbox::Smsg::date($s)."\r\n"
+               }
+       } else {
+               for my $s (@$msgs) {
+                       $tmp .= "$s->{num} $s->{$field}\r\n";
+               }
        }
        utf8::encode($tmp);
        $self->msg_more($tmp);