From 2ac2023fa416e31189708c355db8728abbd9ef2c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 28 Feb 2016 11:28:33 +0000 Subject: reduce calls to close unless error checks are needed We can rely on timely auto-destruction based on reference counting; reducing the chance of redundant close(2) calls which may hit the wront FD. We do care about certain close calls (e.g. writing to a buffered IO handle) if we require error-checking for write-integrity. In other cases, let things go out-of-scope so it can be freed automatically after use. --- lib/PublicInbox/Git.pm | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'lib/PublicInbox/Git.pm') diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 57d17d33..0f92dd9a 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -29,8 +29,6 @@ sub _bidi_pipe { my @cmd = ('git', "--git-dir=$self->{git_dir}", qw(cat-file), $batch); my $redir = { 0 => fileno($out_r), 1 => fileno($in_w) }; $self->{$pid} = spawn(\@cmd, undef, $redir); - close $out_r or fail($self, "close failed: $!"); - close $in_w or fail($self, "close failed: $!"); $out_w->autoflush(1); $self->{$out} = $out_w; $self->{$in} = $in_r; @@ -100,13 +98,9 @@ sub check { sub _destroy { my ($self, $in, $out, $pid) = @_; - my $p = $self->{$pid} or return; - $self->{$pid} = undef; + my $p = delete $self->{$pid} or return; foreach my $f ($in, $out) { - my $fh = $self->{$f}; - defined $fh or next; - close $fh; - $self->{$f} = undef; + delete $self->{$f}; } waitpid $p, 0; } -- cgit v1.2.3-24-ge0c7