From 48f6337c6ecc4f0069f147d6bbaafed969e1d19a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 29 Jul 2010 08:06:57 +0000 Subject: fiber/io: reuse buffer in Rainbows::Fiber::IO#each This makes life easier for the lazy GC when proxying large responses (and also improves memory locality). --- lib/rainbows/fiber/io.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/rainbows/fiber/io.rb b/lib/rainbows/fiber/io.rb index 596aeae..4175eb0 100644 --- a/lib/rainbows/fiber/io.rb +++ b/lib/rainbows/fiber/io.rb @@ -24,11 +24,11 @@ module Rainbows # for wrapping output response bodies def each(&block) - begin - yield readpartial(16384) + if buf = readpartial(16384) + yield buf + yield buf while readpartial(16384, buf) + end rescue EOFError - break - end while true self end -- cgit v1.2.3-24-ge0c7