From 27a288ff1033ae446e1d58d7c510bf9d1cf00961 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 23 Jan 2022 21:28:47 +0000 Subject: do not check IO#closed? before calling IO#close IO#close is idempotent since Ruby 2.3, so reduce our instruction footprint to save some memory. --- bin/dtas-readahead | 2 +- lib/dtas/buffer.rb | 4 ++-- test/test_buffer.rb | 2 +- test/test_unixserver.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/dtas-readahead b/bin/dtas-readahead index 75bfbe8..6da5f88 100755 --- a/bin/dtas-readahead +++ b/bin/dtas-readahead @@ -205,7 +205,7 @@ begin timeout = 0 if timeout < 0 else work.each_value(&:close).clear - fp.close if fp && !fp.closed? + fp.close if fp fp = timeout = nil end r = w.to_io.wait_readable(timeout) diff --git a/lib/dtas/buffer.rb b/lib/dtas/buffer.rb index 54487c5..0688af9 100644 --- a/lib/dtas/buffer.rb +++ b/lib/dtas/buffer.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2020 all contributors +# Copyright (C) all contributors # License: GPL-3.0+ # frozen_string_literal: true require 'io/wait' @@ -45,7 +45,7 @@ class DTAS::Buffer # :nodoc: def __dst_error(dst, e) warn "dropping #{dst.inspect} due to error: #{e.message} (#{e.class})" - dst.close unless dst.closed? + dst.close end # This will modify targets diff --git a/test/test_buffer.rb b/test/test_buffer.rb index b89a090..a47e2d4 100644 --- a/test/test_buffer.rb +++ b/test/test_buffer.rb @@ -11,7 +11,7 @@ class TestBuffer < Testcase @@max_size = nil if @@max_size == 0 def teardown - @to_close.each { |io| io.close unless io.closed? } + @to_close.each(&:close) end def setup diff --git a/test/test_unixserver.rb b/test/test_unixserver.rb index b061af0..7e99b9e 100644 --- a/test/test_unixserver.rb +++ b/test/test_unixserver.rb @@ -21,7 +21,7 @@ class TestUNIXServer < Testcase end def teardown - @clients.each { |io| io.close unless io.closed? } + @clients.each(&:close) if File.exist?(@tmp.path) @tmp.close! else -- cgit v1.2.3-24-ge0c7