From 58dbf0952b94b01d4a434fa880755f9a320c6103 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 7 Jan 2011 10:27:30 -0800 Subject: favor Hash#include? for some existence checks Hash#[] is slightly slower on the miss case due to calling Hash#default (but faster for the hit case, probably because it is inlined in 1.9). --- lib/rainbows/dev_fd_response.rb | 2 +- lib/rainbows/ev_core.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/rainbows') diff --git a/lib/rainbows/dev_fd_response.rb b/lib/rainbows/dev_fd_response.rb index 2f7b1cf..60b595e 100644 --- a/lib/rainbows/dev_fd_response.rb +++ b/lib/rainbows/dev_fd_response.rb @@ -47,7 +47,7 @@ class Rainbows::DevFdResponse < Struct.new(:app) headers['Content-Length'] ||= st.size.to_s headers.delete('Transfer-Encoding') elsif st.pipe? || st.socket? # epoll-able things - unless headers['Content-Length'] + unless headers.include?('Content-Length') if env['rainbows.autochunk'] headers['Transfer-Encoding'] = 'chunked' else diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb index a9fc41e..66d177f 100644 --- a/lib/rainbows/ev_core.rb +++ b/lib/rainbows/ev_core.rb @@ -50,7 +50,7 @@ module Rainbows::EvCore # returns whether to enable response chunking for autochunk models def stream_response_headers(status, headers, alive) headers = Rack::Utils::HeaderHash.new(headers) - if headers[Content_Length] + if headers.include?(Content_Length) rv = false else rv = !!(headers[Transfer_Encoding] =~ %r{\Achunked\z}i) -- cgit v1.2.3-24-ge0c7