nntp: use substr to check for trailing CRLF
authorEric Wong <e@80x24.org>
Sat, 23 Jul 2022 06:13:07 +0000 (06:13 +0000)
committerEric Wong <e@80x24.org>
Sat, 23 Jul 2022 14:22:36 +0000 (14:22 +0000)
Regexps consume more CPU cycles and memory, and aren't
necessary here since we just converted the entire buffer
to CRLF.

lib/PublicInbox/NNTP.pm

index 8ad7adc1fd0a3ca49a5635dc19c8b4c7c95b6c01..b223eb07d417bad27115bcf5411090f4e9ab257c 100644 (file)
@@ -502,7 +502,7 @@ sub msg_body_write ($$) {
        # these can momentarily double the memory consumption :<
        $$msg =~ s/^\./../smg;
        $$msg =~ s/(?<!\r)\n/\r\n/sg; # Alpine barfs without this
-       $$msg .= "\r\n" unless $$msg =~ /\r\n\z/s;
+       $$msg .= "\r\n" unless substr($$msg, -2, 2) eq "\r\n";
        $self->msg_more($$msg);
 }