From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: yahns-public@yhbt.net Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C1F541F59B; Fri, 23 Jan 2015 02:20:06 +0000 (UTC) Date: Fri, 23 Jan 2015 02:20:06 +0000 From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH] reduce File::Stat object allocations Message-ID: <20150123022006.GA17189@dcvr.yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: Since we only support 1.9.3+, io.stat.size may be simplified to io.size to reduce allocations of File::Stat objects. --- lib/yahns/stream_file.rb | 2 +- test/test_output_buffering.rb | 2 +- test/test_stream_file.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/yahns/stream_file.rb b/lib/yahns/stream_file.rb index bcca0d6..793f0de 100644 --- a/lib/yahns/stream_file.rb +++ b/lib/yahns/stream_file.rb @@ -31,7 +31,7 @@ class Yahns::StreamFile # :nodoc: end end @sf_offset = offset - @sf_count = count || @tmpio.stat.size + @sf_count = count || @tmpio.size @wbuf_persist = persist # whether or not we keep the connection alive @body = body end diff --git a/test/test_output_buffering.rb b/test/test_output_buffering.rb index 4911b21..9e2e400 100644 --- a/test/test_output_buffering.rb +++ b/test/test_output_buffering.rb @@ -123,7 +123,7 @@ class TestOutputBuffering < Testcase def gplv3.each raise "SHOULD NOT BE CALLED" end - size = gplv3.stat.size + size = gplv3.size len = size.to_s ranges = Rack::Utils.byte_ranges(e, size) status = 200 diff --git a/test/test_stream_file.rb b/test/test_stream_file.rb index 7dbd512..54344f4 100644 --- a/test/test_stream_file.rb +++ b/test/test_stream_file.rb @@ -9,7 +9,7 @@ class TestStreamFile < Testcase def test_stream_file fp = File.open("COPYING") - sf = Yahns::StreamFile.new(fp, true, 0, fp.stat.size) + sf = Yahns::StreamFile.new(fp, true, 0, fp.size) refute sf.respond_to?(:close) sf.wbuf_close(nil) assert fp.closed? @@ -18,7 +18,7 @@ class TestStreamFile < Testcase def test_fd fp = File.open("COPYING") obj = DevFD.new("/dev/fd/#{fp.fileno}") - sf = Yahns::StreamFile.new(obj, true, 0, fp.stat.size) + sf = Yahns::StreamFile.new(obj, true, 0, fp.size) io = sf.instance_variable_get :@tmpio assert_instance_of IO, io.to_io assert_equal fp.fileno, io.fileno -- EW -- EW