From 44eb53f5a5f1ea2e5aee93d0caf995f42b3179f7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 6 Feb 2011 01:42:31 +0000 Subject: kill some unnecessary &block usage We were needlessly allocating objects even when using yield. --- lib/rainbows/fiber/io.rb | 2 +- lib/rainbows/fiber/io/methods.rb | 2 +- lib/rainbows/max_body/wrapper.rb | 2 +- lib/rainbows/revactor/proxy.rb | 2 +- lib/rainbows/reverse_proxy/ev_client.rb | 2 +- lib/rainbows/reverse_proxy/synchronous.rb | 2 +- lib/rainbows/sendfile.rb | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/rainbows/fiber/io.rb b/lib/rainbows/fiber/io.rb index 49aef3d..4c7864d 100644 --- a/lib/rainbows/fiber/io.rb +++ b/lib/rainbows/fiber/io.rb @@ -28,7 +28,7 @@ class Rainbows::Fiber::IO end # for wrapping output response bodies - def each(&block) + def each buf = readpartial(16384) yield buf yield buf while readpartial(16384, buf) diff --git a/lib/rainbows/fiber/io/methods.rb b/lib/rainbows/fiber/io/methods.rb index 29c9854..29ee397 100644 --- a/lib/rainbows/fiber/io/methods.rb +++ b/lib/rainbows/fiber/io/methods.rb @@ -16,7 +16,7 @@ module Rainbows::Fiber::IO::Methods end # for wrapping output response bodies - def each(&block) + def each if buf = kgio_read(16384) yield buf yield buf while kgio_read(16384, buf) diff --git a/lib/rainbows/max_body/wrapper.rb b/lib/rainbows/max_body/wrapper.rb index 15faeeb..56ee9fd 100644 --- a/lib/rainbows/max_body/wrapper.rb +++ b/lib/rainbows/max_body/wrapper.rb @@ -7,7 +7,7 @@ class Rainbows::MaxBody::Wrapper @input, @limit, @rbuf = rack_input, limit, '' end - def each(&block) + def each while line = gets yield line end diff --git a/lib/rainbows/revactor/proxy.rb b/lib/rainbows/revactor/proxy.rb index a7d3be1..4715981 100644 --- a/lib/rainbows/revactor/proxy.rb +++ b/lib/rainbows/revactor/proxy.rb @@ -17,7 +17,7 @@ class Rainbows::Revactor::Proxy < Rev::IO end end - def each(&block) + def each # when yield-ing, Revactor::TCP#write may raise EOFError # (instead of Errno::EPIPE), so we need to limit the rescue # to just readpartial and let EOFErrors during yield bubble up diff --git a/lib/rainbows/reverse_proxy/ev_client.rb b/lib/rainbows/reverse_proxy/ev_client.rb index 94e7f82..cf97c4d 100644 --- a/lib/rainbows/reverse_proxy/ev_client.rb +++ b/lib/rainbows/reverse_proxy/ev_client.rb @@ -26,7 +26,7 @@ module Rainbows::ReverseProxy::EvClient end class LargeBody < Tempfile - def each(&block) + def each buf = "" rewind while read(16384, buf) diff --git a/lib/rainbows/reverse_proxy/synchronous.rb b/lib/rainbows/reverse_proxy/synchronous.rb index b5911a9..bbb9ec5 100644 --- a/lib/rainbows/reverse_proxy/synchronous.rb +++ b/lib/rainbows/reverse_proxy/synchronous.rb @@ -3,7 +3,7 @@ module Rainbows::ReverseProxy::Synchronous UpstreamSocket = Rainbows::ReverseProxy::UpstreamSocket - def each_block(input, &block) + def each_block(input) buf = "" while input.read(16384, buf) yield buf diff --git a/lib/rainbows/sendfile.rb b/lib/rainbows/sendfile.rb index 545b85c..767c0f9 100644 --- a/lib/rainbows/sendfile.rb +++ b/lib/rainbows/sendfile.rb @@ -63,7 +63,7 @@ class Rainbows::Sendfile < Struct.new(:app) end # fallback in case our +to_path+ doesn't get handled for whatever reason - def each(&block) + def each buf = '' File.open(to_path) do |fp| yield buf while fp.read(0x4000, buf) -- cgit v1.2.3-24-ge0c7