From 7c88e3e0f4cbfdbc077946b427884311ca314304 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 7 May 2015 21:43:43 +0000 Subject: avoid extra allocation for hijack proc creation proc creation is expensive, so merely use a 48-byte generic ivar hash slot for @socket instead. --- lib/unicorn/http_request.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index b32003e..b60e383 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -97,15 +97,21 @@ class Unicorn::HttpParser e[RACK_INPUT] = 0 == content_length ? NULL_IO : @@input_class.new(socket, self) - hijack_setup(e, socket) + + # for Rack hijacking in Rack 1.5 and later + @socket = socket + e[RACK_HIJACK] = self + e.merge!(DEFAULTS) end - def hijacked? - env.include?(RACK_HIJACK_IO) + # for rack.hijack, we respond to this method so no extra allocation + # of a proc object + def call + env[RACK_HIJACK_IO] = @socket end - def hijack_setup(e, socket) - e[RACK_HIJACK] = proc { e[RACK_HIJACK_IO] = socket } + def hijacked? + env.include?(RACK_HIJACK_IO) end end -- cgit v1.2.3-24-ge0c7