From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 2A55D1F4CC for ; Tue, 12 Nov 2024 20:34:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1731443675; bh=YfW9tiJskayT1JMU1PFYWX/s15Tq0WSdnsoZtKSI43o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ljr919jj43yRQr+F92Uq++8vZIpc3kBLyV5tyPUQhuctRFfq2sPSSFxOqIOhejwmH CJbWM899qXzPXrXuVEQNZTLyhgRhIUhcJWahxb9ZTVtDbjCqq6iAfer/ZuBlR4Ylx+ TBL6ZzwOdrhDDQRGhxVn1ISeYGHCTsDRtHVhEIdo= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/4] lei_mirror: favor File::Spec::Functions Date: Tue, 12 Nov 2024 20:34:33 +0000 Message-ID: <20241112203433.2515907-5-e@80x24.org> In-Reply-To: <20241112203433.2515907-1-e@80x24.org> References: <20241112203433.2515907-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Functions calls are preferable over `->' method dispatch in tight loops. This can be the case when scanning alternates in v1_done(). Since we're at it, replace all other `File::Spec->' method dispatches with function calls since function calls can be used to validate function prototypes at compile time. --- lib/PublicInbox/LeiMirror.pm | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm index fb0295da..f87cdc51 100644 --- a/lib/PublicInbox/LeiMirror.pm +++ b/lib/PublicInbox/LeiMirror.pm @@ -11,7 +11,7 @@ use PublicInbox::Spawn qw(spawn run_wait run_die run_qx); use PublicInbox::IO qw(write_file); use File::Path (); use File::Temp (); -use File::Spec (); +use File::Spec::Functions qw(abs2rel rel2abs splitpath); use Fcntl qw(SEEK_SET O_CREAT O_EXCL O_WRONLY); use Carp qw(croak); use URI; @@ -502,9 +502,9 @@ EOM EOM } if (!$self->{dry_run}) { - my $alt = File::Spec->rel2abs("$dir/objects"); + my $alt = rel2abs "$dir/objects"; my $o = "$self->{cur_dst}/objects"; - my $l = File::Spec->abs2rel($alt, File::Spec->rel2abs($o)); + my $l = abs2rel $alt, rel2abs($o); open my $fh, '+>>', my $f = "$o/info/alternates"; seek($fh, 0, SEEK_SET); # Perl did SEEK_END when it saw '>>' my $seen = grep /\A\Q$l\E\n/, PublicInbox::IO::read_all $fh; @@ -780,15 +780,14 @@ sub update_ent { start_cmd($self, $cmd, { 2 => $self->{lei}->{2} }) if $cmd; } if (my $symlinks = $self->{-ent}->{symlinks}) { - my $top = File::Spec->rel2abs($self->{dst}); + my $top = rel2abs $self->{dst}; push @{$self->{-new_symlinks}}, @$symlinks; for my $p (@$symlinks) { my $ln = "$top/$p"; $ln =~ tr!/!/!s; - my (undef, $dn, $bn) = File::Spec->splitpath($ln); + my (undef, $dn, $bn) = splitpath $ln; File::Path::mkpath($dn); - my $tgt = "$top/$key"; - $tgt = File::Spec->abs2rel($tgt, $dn); + my $tgt = abs2rel "$top/$key", $dn; if (lstat($ln)) { if (-l _) { next if readlink($ln) eq $tgt; @@ -828,12 +827,12 @@ sub v1_done { # called via OnDestroy update_ent($self) if $self->{-ent}; my $o = "$dst/objects"; if (CORE::open(my $fh, '<', my $fn = "$o/info/alternates")) {; - my $base = File::Spec->rel2abs($o); + my $base = rel2abs $o; my @l = <$fh>; my $ft; for (@l) { next unless m!\A/!; - $_ = File::Spec->abs2rel($_, $base); + $_ = abs2rel $_, $base; $ft //= File::Temp->new(TEMPLATE => '.XXXX', DIR => "$o/info"); } @@ -1123,7 +1122,7 @@ EOM } $self->{chg}->{nr_chg} += scalar(@remote) + scalar(@local); return if !defined($f) || $self->{dry_run}; - my (undef, $dn, $bn) = File::Spec->splitpath($f); + my (undef, $dn, $bn) = splitpath $f; my $new = join("\n", @list, ''); atomic_write($dn, $bn, $new) if $new ne $old; }