From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id C19961F852 for ; Sun, 23 Jan 2022 21:38:40 +0000 (UTC) Received: from localhost ([::1]:56748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nBkZM-0007f8-0R for e@80x24.org; Sun, 23 Jan 2022 16:38:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nBkZI-0007cy-6h for dtas-all@nongnu.org; Sun, 23 Jan 2022 16:38:38 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:40240) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nBkZG-0000CI-Mu for dtas-all@nongnu.org; Sun, 23 Jan 2022 16:38:35 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6FA391FB05 for ; Sun, 23 Jan 2022 21:37:47 +0000 (UTC) From: Eric Wong 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 Message-Id: <20220123213746.21085-10-e@80x24.org> In-Reply-To: <20220123213746.21085-1-e@80x24.org> References: <20220123213746.21085-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=64.71.152.64; envelope-from=e@80x24.org; helo=dcvr.yhbt.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: duct tape audio suite List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+e=80x24.org@nongnu.org Sender: "dtas-all" 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 +# Copyright (C) all contributors # License: GPL-3.0+ # 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