From: Eric Wong Date: Thu, 27 Mar 2025 23:20:46 +0000 (+0000) Subject: nntp: avoid repeated rand() calls X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f6a55088d76f94987116cad6c355e86b553e68f;p=thirdparty%2Fpublic-inbox.git nntp: avoid repeated rand() calls We only need to generate the secret salt once, so initialize it early to avoid potentially expensive `rand' ops in repeated calls to wildmat2re. We'll also stringify it early to hopefully improve CoW sharing and reduce fragmentation. --- diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index eab6d301d..07d86d603 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -19,6 +19,7 @@ use PublicInbox::SHA qw(sha1_hex); use Time::Local qw(timegm timelocal); use PublicInbox::GitAsyncCat; use PublicInbox::Address; +my $SALT = rand . ''; # stringify early for CoW sharing use constant { LINE_MAX => 512, # RFC 977 section 2.3 @@ -278,11 +279,10 @@ sub wildmat2re ($) { my $tmp = $_[0] // '*'; return qr/.*/ if $tmp eq '*'; my %keep; - my $salt = rand; $tmp =~ s#(?