From 70c976bdd85bb8515fea01d6ad6074ef472fc2e0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 14 Nov 2015 02:47:24 +0000 Subject: reduce constant lookup dependencies Unicorn 5 removes some constants we were using, and constant lookups + inline caching are waste of time anyways on newer Rubies with the opt_str_freeze bytecode instruction. This may reduce performance for folks on older Rubies (probably not noticeable); but improves performance for folks on newer Rubies. --- lib/rainbows/dev_fd_response.rb | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 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 7baccfc..8ebaabd 100644 --- a/lib/rainbows/dev_fd_response.rb +++ b/lib/rainbows/dev_fd_response.rb @@ -11,12 +11,6 @@ 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_VERSION = "HTTP_VERSION" - Chunked = "chunked" include Rack::Utils # Rack middleware entry point, we'll just pass through responses @@ -40,23 +34,23 @@ 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'.freeze] ||= st.size.to_s + headers.delete('Transfer-Encoding'.freeze) elsif st.pipe? || st.socket? # epoll-able things - unless headers.include?(Content_Length) - if env[Rainbows_autochunk] - case env[HTTP_VERSION] + unless headers.include?('Content-Length'.freeze) + if env['rainbows.autochunk'] + case env['HTTP_VERSION'] when "HTTP/1.0", nil else - headers[Transfer_Encoding] = Chunked + headers['Transfer-Encoding'.freeze] = 'chunked' end 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