From fa0b3774dd9cd73331e83b3517c37964ab265074 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 20 Jan 2011 02:13:38 -0800 Subject: dev_fd_response: garbage reduction Constant strings mean the runtime won't have to allocate new objects all the time since GC is currently the biggest performance problem of Ruby 1.9.x in my experience. --- lib/rainbows/dev_fd_response.rb | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/rainbows/dev_fd_response.rb') diff --git a/lib/rainbows/dev_fd_response.rb b/lib/rainbows/dev_fd_response.rb index a42697d..1ee3375 100644 --- a/lib/rainbows/dev_fd_response.rb +++ b/lib/rainbows/dev_fd_response.rb @@ -15,6 +15,13 @@ class Rainbows::DevFdResponse < Struct.new(:app) # :stopdoc: FD_MAP = Rainbows::FD_MAP + Content_Length = "Content-Length".freeze + Transfer_Encoding = "Transfer-Encoding".freeze + Rainbows_autochunk = "rainbows.autochunk".freeze + Rainbows_model = "rainbows.model" + HTTP_1_0 = "HTTP/1.0" + HTTP_VERSION = "HTTP_VERSION" + Chunked = "chunked" # make this a no-op under Rubinius, it's pointless anyways # since Rubinius doesn't have IO.copy_stream @@ -44,19 +51,19 @@ class Rainbows::DevFdResponse < Struct.new(:app) fileno = io.fileno FD_MAP[fileno] = io if st.file? - headers['Content-Length'] ||= st.size.to_s - headers.delete('Transfer-Encoding') + headers[Content_Length] ||= st.size.to_s + headers.delete(Transfer_Encoding) elsif st.pipe? || st.socket? # epoll-able things - unless headers.include?('Content-Length') - if env['rainbows.autochunk'] && "HTTP/1.0" != env["HTTP_VERSION"] - headers['Transfer-Encoding'] = 'chunked' + unless headers.include?(Content_Length) + if env[Rainbows_autochunk] && HTTP_1_0 != env[HTTP_VERSION] + headers[Transfer_Encoding] = Chunked else - env['rainbows.autochunk'] = false + env[Rainbows_autochunk] = false end end # we need to make sure our pipe output is Fiber-compatible - case env["rainbows.model"] + case env[Rainbows_model] when :FiberSpawn, :FiberPool, :RevFiberSpawn, :CoolioFiberSpawn io.respond_to?(:kgio_wait_readable) or io = Rainbows::Fiber::IO.new(io) -- cgit v1.2.3-24-ge0c7