From 709a1979302ef5dbb40babb84821b079868490a1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 30 Sep 2015 21:00:19 +0000 Subject: remove unnecessary fields usage It doesn't actually give performance improvements unless we use types with "my", but we don't do that. We'll only continue using fields with Danga::Socket-derived classes where they're required. --- lib/PublicInbox/GitCatFile.pm | 5 +---- lib/PublicInbox/Hval.pm | 9 ++++----- lib/PublicInbox/Mbox.pm | 11 +++++------ lib/PublicInbox/Msgmap.pm | 4 +--- lib/PublicInbox/NewsGroup.pm | 10 +++++----- lib/PublicInbox/SearchView.pm | 19 ++++++++----------- 6 files changed, 24 insertions(+), 34 deletions(-) (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/GitCatFile.pm b/lib/PublicInbox/GitCatFile.pm index 54036961..629d23ed 100644 --- a/lib/PublicInbox/GitCatFile.pm +++ b/lib/PublicInbox/GitCatFile.pm @@ -8,13 +8,10 @@ use strict; use warnings; use POSIX qw(dup2); require IO::Handle; -use fields qw(git_dir pid in out); sub new { my ($class, $git_dir) = @_; - my $self = fields::new($class); - $self->{git_dir} = $git_dir; - $self; + bless { git_dir => $git_dir }, $class } sub _cat_file_begin { diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm index e0ec6305..9fbe616f 100644 --- a/lib/PublicInbox/Hval.pm +++ b/lib/PublicInbox/Hval.pm @@ -5,7 +5,6 @@ package PublicInbox::Hval; use strict; use warnings; -use fields qw(raw href); use Encode qw(find_encoding); use URI::Escape qw(uri_escape_utf8); use PublicInbox::MID qw/mid_clean/; @@ -14,14 +13,14 @@ my $enc_ascii = find_encoding('us-ascii'); sub new { my ($class, $raw, $href) = @_; - my $self = fields::new($class); # we never care about leading/trailing whitespace $raw =~ s/\A\s*//; $raw =~ s/\s*\z//; - $self->{raw} = $raw; - $self->{href} = defined $href ? $href : $raw; - $self; + bless { + raw => $raw, + href => defined $href ? $href : $raw, + }, $class; } sub new_msgid { diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm index c92d4447..8bb8dc83 100644 --- a/lib/PublicInbox/Mbox.pm +++ b/lib/PublicInbox/Mbox.pm @@ -110,16 +110,15 @@ EOF package PublicInbox::MboxGz; use strict; use warnings; -use fields qw(gz fh buf); sub new { my ($class, $fh) = @_; - my $self = fields::new($class); my $buf; - $self->{buf} = \$buf; - $self->{gz} = IO::Compress::Gzip->new(\$buf); - $self->{fh} = $fh; - $self; + bless { + buf => \$buf, + gz => IO::Compress::Gzip->new(\$buf), + fh => $fh, + }, $class; } sub _flush_buf { diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm index f2857908..8a34e7e0 100644 --- a/lib/PublicInbox/Msgmap.pm +++ b/lib/PublicInbox/Msgmap.pm @@ -4,7 +4,6 @@ package PublicInbox::Msgmap; use strict; use warnings; -use fields qw(dbh mid_insert mid_for num_for num_minmax); use DBI; use DBD::SQLite; @@ -23,8 +22,7 @@ sub new { sqlite_use_immediate_transaction => 1, }); $dbh->do('PRAGMA case_sensitive_like = ON'); - my $self = fields::new($class); - $self->{dbh} = $dbh; + my $self = bless { dbh => $dbh }, $class; if ($writable) { create_tables($dbh); diff --git a/lib/PublicInbox/NewsGroup.pm b/lib/PublicInbox/NewsGroup.pm index 0c7051db..1250b0d8 100644 --- a/lib/PublicInbox/NewsGroup.pm +++ b/lib/PublicInbox/NewsGroup.pm @@ -3,7 +3,6 @@ package PublicInbox::NewsGroup; use strict; use warnings; -use fields qw(name git_dir address domain mm gcf search); use Scalar::Util qw(weaken); require Danga::Socket; require PublicInbox::Msgmap; @@ -11,12 +10,13 @@ require PublicInbox::GitCatFile; sub new { my ($class, $name, $git_dir, $address) = @_; - my $self = fields::new($class); - $self->{name} = $name; $address = $address->[0] if ref($address); + my $self = bless { + name => $name, + git_dir => $git_dir, + address => $address, + }, $class; $self->{domain} = ($address =~ /\@(\S+)\z/) ? $1 : 'localhost'; - $self->{git_dir} = $git_dir; - $self->{address} = $address; $self; } diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 6bc66ceb..cfc650f4 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -257,27 +257,24 @@ sub adump { package PublicInbox::SearchQuery; use strict; use warnings; -use fields qw(q o t x r); use PublicInbox::Hval; sub new { my ($class, $cgi) = @_; - my $self = fields::new($class); - $self->{q} = $cgi->param('q'); - $self->{x} = $cgi->param('x') || ''; - $self->{o} = int($cgi->param('o') || 0) || 0; - my $r = $cgi->param('r'); - $self->{r} = (defined $r && $r ne '0'); - - $self; + my $r => $cgi->param('r'), + bless { + q => $cgi->param('q'), + x => $cgi->param('x') || '', + o => int($cgi->param('o') || 0) || 0, + r => (defined $r && $r ne '0'), + }, $class; } sub qs_html { my ($self, %over) = @_; if (keys %over) { - my $tmp = fields::new(ref($self)); - %$tmp = %$self; + my $tmp = bless { %$self }, ref($self); foreach my $k (keys %over) { $tmp->{$k} = $over{$k}; } -- cgit v1.2.3-24-ge0c7