]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Git.pm
git: reduce delete ops in _destroy
[public-inbox.git] / lib / PublicInbox / Git.pm
index ff3ac40f59511aab560b114d4ad73eecc3f067b2..12f997dc147ec80278392aa7cf088ef59d30ce26 100644 (file)
@@ -12,7 +12,7 @@ use v5.10.1;
 use parent qw(Exporter);
 use POSIX ();
 use IO::Handle; # ->autoflush
-use Errno qw(EINTR EAGAIN ENOENT);
+use Errno qw(EINTR EAGAIN);
 use File::Glob qw(bsd_glob GLOB_NOSORT);
 use File::Spec ();
 use Time::HiRes qw(stat);
@@ -156,6 +156,7 @@ sub _bidi_pipe {
                $self->{$err} = $fh;
                $rdr->{2} = $fh;
        }
+       # see lib/PublicInbox/ProcessPipe.pm for why we don't use that here
        my ($in_r, $p) = popen_rd(\@cmd, undef, $rdr);
        awaitpid($self->{$pid} = $p, undef);
        $self->{"$pid.owner"} = $$;
@@ -372,13 +373,11 @@ sub check {
 }
 
 sub _destroy {
-       my ($self, $rbuf, $in, $out, $pid, $err) = @_;
-       delete @$self{($rbuf, $in, $out)};
-       delete $self->{$err} if $err; # `err_c'
+       my ($self, $pid, @rest) = @_; # rest = rbuf, in, out, err
+       my ($p) = delete @$self{($pid, @rest)};
 
        # GitAsyncCat::event_step may delete {$pid}
-       my $p = delete($self->{$pid}) // return;
-       awaitpid($p) if $$ == $self->{"$pid.owner"};
+       awaitpid($p) if defined($p) && $$ == $self->{"$pid.owner"};
 }
 
 sub async_abort ($) {
@@ -467,8 +466,8 @@ sub cleanup {
        async_wait_all($self);
        delete $self->{inflight};
        delete $self->{inflight_c};
-       _destroy($self, qw(rbuf in out pid));
-       _destroy($self, qw(rbuf_c in_c out_c pid_c err_c));
+       _destroy($self, qw(pid rbuf in out));
+       _destroy($self, qw(pid_c rbuf_c in_c out_c err_c));
        undef;
 }