From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 04/12] remove unnecessary fields usage
Date: Wed, 30 Sep 2015 21:00:19 +0000 [thread overview]
Message-ID: <20150930210027.30479-5-e@80x24.org> (raw)
In-Reply-To: <20150930210027.30479-1-e@80x24.org>
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 ++++++++-----------
public-inbox-nntpd | 13 ++++++-------
7 files changed, 30 insertions(+), 41 deletions(-)
diff --git a/lib/PublicInbox/GitCatFile.pm b/lib/PublicInbox/GitCatFile.pm
index 5403696..629d23e 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 e0ec630..9fbe616 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 c92d444..8bb8dc8 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 f285790..8a34e7e 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 0c7051d..1250b0d 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 6bc66ce..cfc650f 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};
}
diff --git a/public-inbox-nntpd b/public-inbox-nntpd
index f6042c2..79161fb 100644
--- a/public-inbox-nntpd
+++ b/public-inbox-nntpd
@@ -15,16 +15,15 @@ daemon_run('0.0.0.0:119',
package PublicInbox::NNTPD;
use strict;
use warnings;
-use fields qw(groups grouplist err out);
sub new {
my ($class) = @_;
- my $self = fields::new($class);
- $self->{groups} = {};
- $self->{err} = \*STDERR;
- $self->{out} = \*STDOUT;
- $self->{grouplist} = [];
- $self;
+ bless {
+ groups => {},
+ err => \*STDERR,
+ out => \*STDOUT,
+ grouplist => [],
+ }, $class;
}
sub refresh_groups () {
--
EW
next prev parent reply other threads:[~2015-09-30 21:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-30 21:00 [PATCH 0/12] another round of NNTP updates Eric Wong
2015-09-30 21:00 ` [PATCH 01/12] search: remove get_subject_path Eric Wong
2015-09-30 21:00 ` [PATCH 02/12] nntp: HDR returns 225, not 224 Eric Wong
2015-09-30 21:00 ` [PATCH 03/12] nntp: reduce syscalls for LIST OVERVIEW.FMT Eric Wong
2015-09-30 21:00 ` Eric Wong [this message]
2015-09-30 21:00 ` [PATCH 05/12] daemon: always autoflush stdout/stderr Eric Wong
2015-09-30 21:00 ` [PATCH 06/12] nntpd: avoid lazy require Eric Wong
2015-09-30 21:00 ` [PATCH 07/12] INSTALL: document Danga::Socket dependency for nntpd Eric Wong
2015-09-30 21:00 ` [PATCH 08/12] nntp: MODE READER denies posting Eric Wong
2015-09-30 21:00 ` [PATCH 09/12] nntp: implement LIST HEADERS Eric Wong
2015-09-30 21:00 ` [PATCH 10/12] nntp: implement OVER/XOVER summary in search document Eric Wong
2015-09-30 21:00 ` [PATCH 11/12] t/nntpd.t: simplify condition for response termination Eric Wong
2015-09-30 21:00 ` [PATCH 12/12] t/nntpd.t: additional tests for XHDR/HDR Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150930210027.30479-5-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).