* [PATCH] reduce File::Stat object allocations
@ 2015-01-23 2:20 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-01-23 2:20 UTC (permalink / raw)
To: yahns-public
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-01-23 2:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-23 2:20 [PATCH] reduce File::Stat object allocations Eric Wong
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).