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/sendfile.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'lib/rainbows/sendfile.rb') diff --git a/lib/rainbows/sendfile.rb b/lib/rainbows/sendfile.rb index 767c0f9..59906e2 100644 --- a/lib/rainbows/sendfile.rb +++ b/lib/rainbows/sendfile.rb @@ -52,12 +52,10 @@ class Rainbows::Sendfile < Struct.new(:app) # +each+ in case a given concurrency model does not optimize # +to_path+ calls. class Body < Struct.new(:to_path) # :nodoc: all - CONTENT_LENGTH = 'Content-Length'.freeze - def self.new(path, headers) - unless headers[CONTENT_LENGTH] + unless headers['Content-Length'.freeze] stat = File.stat(path) - headers[CONTENT_LENGTH] = stat.size.to_s if stat.file? + headers['Content-Length'.freeze] = stat.size.to_s if stat.file? end super(path) end @@ -71,14 +69,10 @@ class Rainbows::Sendfile < Struct.new(:app) end end - # :stopdoc: - X_SENDFILE = 'X-Sendfile' - # :startdoc: - def call(env) # :nodoc: status, headers, body = app.call(env) headers = Rack::Utils::HeaderHash.new(headers) unless Hash === headers - if path = headers.delete(X_SENDFILE) + if path = headers.delete('X-Sendfile'.freeze) body = Body.new(path, headers) unless body.respond_to?(:to_path) end [ status, headers, body ] -- cgit v1.2.3-24-ge0c7