From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 25B151F71A for ; Mon, 30 May 2016 04:54:03 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] use utf8::{encode,decode} for in-place transforms Date: Mon, 30 May 2016 04:54:03 +0000 Message-Id: <20160530045403.22198-1-e@80x24.org> List-Id: No need to duplicate the string when transforming it; learned from studying SpamAssassin 3.4.1 --- lib/PublicInbox/NNTP.pm | 6 ++---- lib/PublicInbox/SearchMsg.pm | 4 +--- lib/PublicInbox/View.pm | 1 - 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 232237c..e4e3de4 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -16,8 +16,6 @@ use Email::Simple; use POSIX qw(strftime); use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC); use URI::Escape qw(uri_escape_utf8); -use Encode qw(find_encoding); -my $enc_utf8 = find_encoding('UTF-8'); use constant { r501 => '501 command syntax error', r221 => '221 Header follows', @@ -898,7 +896,7 @@ sub cmd_xpath ($$) { sub res ($$) { my ($self, $line) = @_; - $line = $enc_utf8->encode($line); + utf8::encode($line); do_write($self, $line . "\r\n"); } @@ -933,7 +931,7 @@ use constant MSG_MORE => ($^O eq 'linux') ? 0x8000 : 0; sub do_more ($$) { my ($self, $data) = @_; - $data = $enc_utf8->encode($data); + utf8::encode($data); if (MSG_MORE && !$self->{write_buf_size}) { my $n = send($self->{sock}, $data, MSG_MORE); if (defined $n) { diff --git a/lib/PublicInbox/SearchMsg.pm b/lib/PublicInbox/SearchMsg.pm index caebe37..28c2037 100644 --- a/lib/PublicInbox/SearchMsg.pm +++ b/lib/PublicInbox/SearchMsg.pm @@ -11,8 +11,6 @@ use POSIX qw//; use Date::Parse qw/str2time/; use PublicInbox::MID qw/mid_clean/; use PublicInbox::Address; -use Encode qw/find_encoding/; -my $enc_utf8 = find_encoding('UTF-8'); our $PFX2TERM_RE = undef; use constant EPOCH_822 => 'Thu, 01 Jan 1970 00:00:00 +0000'; use POSIX qw(strftime); @@ -39,7 +37,7 @@ sub load_doc { my ($class, $doc) = @_; my $data = $doc->get_data; my $ts = get_val($doc, &PublicInbox::Search::TS); - $data = $enc_utf8->decode($data); + utf8::decode($data); my ($subj, $from, $refs, $to, $cc) = split(/\n/, $data); bless { doc => $doc, diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index a78ce31..ed40530 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -8,7 +8,6 @@ use strict; use warnings; use URI::Escape qw/uri_escape_utf8/; use Date::Parse qw/str2time/; -use Encode qw/find_encoding/; use Encode::MIME::Header; use PublicInbox::Hval qw/ascii_html/; use PublicInbox::Linkify;