From ff0fc020fe30798e52d96cc11b445c76d9822422 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 3 Jul 2009 22:30:48 -0700 Subject: Favor Struct members to instance variables There's a small memory reduction to be had when forking oodles of processes and the Perl hacker in me still gets confused into thinking those are arrays... --- examples/echo.ru | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/echo.ru b/examples/echo.ru index 322fe94..c79cb7b 100644 --- a/examples/echo.ru +++ b/examples/echo.ru @@ -8,25 +8,20 @@ # # Then type random stuff in your terminal to watch it get echoed back! -class EchoBody - def initialize(input) - @input = input - end +class EchoBody < Struct.new(:input) def each(&block) - while buf = @input.read(4096) + while buf = input.read(4096) yield buf end self end - def close - @input = nil - end end use Rack::Chunked run lambda { |env| + /\A100-continue\z/ =~ env['HTTP_EXPECT'] and return [100, {}, []] [ 200, { 'Content-Type' => 'application/octet-stream' }, EchoBody.new(env['rack.input']) ] } -- cgit v1.2.3-24-ge0c7