user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Subject: [PATCH 4/7] config: avoid unnecessary '||' use
Date: Tue, 15 Oct 2019 20:36:30 +0000	[thread overview]
Message-ID: <20191015203633.17665-5-e@80x24.org> (raw)
In-Reply-To: <20191015203633.17665-1-e@80x24.org>

'//' is available in Perl 5.10+ which allows `0' and `""' (empty
string) to remain unclobbered.

We also don't need '||=' for initializing our internal caches.
---
 lib/PublicInbox/Config.pm | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 2b99346a..e0329ebf 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -29,13 +29,13 @@ sub new {
 	}
 	bless $self, $class;
 	# caches
-	$self->{-by_addr} ||= {};
-	$self->{-by_list_id} ||= {};
-	$self->{-by_name} ||= {};
-	$self->{-by_newsgroup} ||= {};
-	$self->{-no_obfuscate} ||= {};
-	$self->{-limiters} ||= {};
-	$self->{-code_repos} ||= {}; # nick => PublicInbox::Git object
+	$self->{-by_addr} = {};
+	$self->{-by_list_id} = {};
+	$self->{-by_name} = {};
+	$self->{-by_newsgroup} = {};
+	$self->{-no_obfuscate} = {};
+	$self->{-limiters} = {};
+	$self->{-code_repos} = {}; # nick => PublicInbox::Git object
 	$self->{-cgitrc_unparsed} = $self->{'publicinbox.cgitrc'};
 
 	if (my $no = delete $self->{'publicinbox.noobfuscate'}) {
@@ -85,7 +85,7 @@ sub lookup_list_id {
 
 sub lookup_name ($$) {
 	my ($self, $name) = @_;
-	$self->{-by_name}->{$name} || _fill($self, "publicinbox.$name");
+	$self->{-by_name}->{$name} // _fill($self, "publicinbox.$name");
 }
 
 sub each_inbox {
@@ -106,7 +106,7 @@ sub lookup_newsgroup {
 
 sub limiter {
 	my ($self, $name) = @_;
-	$self->{-limiters}->{$name} ||= do {
+	$self->{-limiters}->{$name} //= do {
 		require PublicInbox::Qspawn;
 		my $max = $self->{"publicinboxlimiter.$name.max"} || 1;
 		my $limiter = PublicInbox::Qspawn::Limiter->new($max);
@@ -115,7 +115,7 @@ sub limiter {
 	};
 }
 
-sub config_dir { $ENV{PI_DIR} || "$ENV{HOME}/.public-inbox" }
+sub config_dir { $ENV{PI_DIR} // "$ENV{HOME}/.public-inbox" }
 
 sub default_file {
 	my $f = $ENV{PI_CONFIG};
@@ -206,8 +206,8 @@ sub cgit_repo_merge ($$$) {
 		$self->{-cgit_remove_suffix} and
 			$rel =~ s!/?\.git\z!!;
 	}
-	$self->{"coderepo.$rel.dir"} ||= $path;
-	$self->{"coderepo.$rel.cgiturl"} ||= $rel;
+	$self->{"coderepo.$rel.dir"} //= $path;
+	$self->{"coderepo.$rel.cgiturl"} //= $rel;
 }
 
 sub is_git_dir ($) {
@@ -338,7 +338,7 @@ sub _fill_code_repo {
 		# cgit supports "/blob/?id=%s", but it's only a plain-text
 		# display and requires an unabbreviated id=
 		foreach my $t (qw(blob commit tag)) {
-			$git->{$t.'_url_format'} ||= map {
+			$git->{$t.'_url_format'} //= map {
 				"$_/$t/?id=%s"
 			} @$cgits;
 		}
@@ -426,7 +426,7 @@ sub _fill {
 			$valid += valid_inbox_name($_) foreach (@parts);
 			$valid == scalar(@parts) or next;
 
-			my $repo = $code_repos->{$nick} ||=
+			my $repo = $code_repos->{$nick} //=
 						_fill_code_repo($self, $nick);
 			push @$repo_objs, $repo if $repo;
 		}

  parent reply	other threads:[~2019-10-15 20:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-15 20:36 [PATCH 0/7] List-ID support in mda, watch, www Eric Wong
2019-10-15 20:36 ` [PATCH 1/7] Config.pm: Add support for mailing list information Eric Wong
2019-10-15 20:36 ` [PATCH 2/7] config: we always have {-section_order} Eric Wong
2019-10-15 20:36 ` [PATCH 3/7] config: simplify lookup* methods Eric Wong
2019-10-15 20:36 ` Eric Wong [this message]
2019-10-15 20:36 ` [PATCH 5/7] config: allow "0" as a valid mainrepo path Eric Wong
2019-10-15 20:36 ` [PATCH 6/7] mda, watch: wire up List-ID header support Eric Wong
2019-10-15 20:36 ` [PATCH 7/7] wwwtext: show listid config directive(s) 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=20191015203633.17665-5-e@80x24.org \
    --to=e@80x24.org \
    --cc=ebiederm@xmission.com \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).