yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH] reduce File::Stat object allocations
Date: Fri, 23 Jan 2015 02:20:06 +0000	[thread overview]
Message-ID: <20150123022006.GA17189@dcvr.yhbt.net> (raw)

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

                 reply	other threads:[~2015-01-23  2:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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://yhbt.net/yahns/README

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

  git send-email \
    --in-reply-to=20150123022006.GA17189@dcvr.yhbt.net \
    --to=e@80x24.org \
    --cc=yahns-public@yhbt.net \
    /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://yhbt.net/yahns.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).