everything related to duct tape audio suite (dtas)
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: dtas-all@nongnu.org
Subject: [PATCH 9/9] do not check IO#closed? before calling IO#close
Date: Sun, 23 Jan 2022 21:37:46 +0000	[thread overview]
Message-ID: <20220123213746.21085-10-e@80x24.org> (raw)
In-Reply-To: <20220123213746.21085-1-e@80x24.org>

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 @@ def do_open(path)
     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 <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 require 'io/wait'
@@ -45,7 +45,7 @@ def to_hsh
 
   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 @@ def test_close
   end
 
   def teardown
-    @clients.each { |io| io.close unless io.closed? }
+    @clients.each(&:close)
     if File.exist?(@tmp.path)
       @tmp.close!
     else


      parent reply	other threads:[~2022-01-23 21:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-23 21:37 [PATCH 0/9] various cuts for memory savings Eric Wong
2022-01-23 21:37 ` [PATCH 1/9] deduplicate and freeze pathnames + metadata Eric Wong
2022-01-23 21:37 ` [PATCH 2/9] player: remove omap conversion Eric Wong
2022-01-23 21:37 ` [PATCH 3/9] dtas: drop unnecessary "require 'yaml'" statements Eric Wong
2022-01-23 21:37 ` [PATCH 4/9] dtas-tl prune: cull missing files from tracklist Eric Wong
2022-01-23 21:37 ` [PATCH 5/9] dtas-tl: drop encoding hacks, use binary stdout+stderr Eric Wong
2022-01-23 21:37 ` [PATCH 6/9] use IO#wait_readable consistently Eric Wong
2022-01-23 21:37 ` [PATCH 7/9] get rid of DTAS::Nonblock wrapper for Ruby <= 2.0 Eric Wong
2022-01-23 21:37 ` [PATCH 8/9] unix_accepted: drop Ruby < 2.3 support code Eric Wong
2022-01-23 21:37 ` Eric Wong [this message]

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://80x24.org/dtas/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220123213746.21085-10-e@80x24.org \
    --to=e@80x24.org \
    --cc=dtas-all@nongnu.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/dtas.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).