From 2c913347a6e5cc8be776b14e1a177adec0fbd5b6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 17 Jan 2011 03:17:28 +0000 Subject: use constants everywhere to reduce GC thrashing This makes it easier to notice a typo, too. --- lib/metropolis/common.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/metropolis/common.rb') diff --git a/lib/metropolis/common.rb b/lib/metropolis/common.rb index a6688f3..383ebe9 100644 --- a/lib/metropolis/common.rb +++ b/lib/metropolis/common.rb @@ -1,10 +1,13 @@ # -*- encoding: binary -*- module Metropolis::Common include Rack::Utils # unescape + include Metropolis::Constants + HTTP_STATUS_BODIES = {} + autoload :RO, 'metropolis/common/ro' def setup(opts) - @headers = { 'Content-Type' => 'application/octet-stream' } + @headers = { Content_Type => 'application/octet-stream' } @headers.merge!(opts[:response_headers] || {}) @nr_slots = opts[:nr_slots] @@ -39,16 +42,16 @@ module Metropolis::Common end def r(code, body = nil) - body ||= "#{HTTP_STATUS_CODES[code]}\n" + body ||= HTTP_STATUS_BODIES[code] ||= "#{HTTP_STATUS_CODES[code]}\n" [ code, - { 'Content-Length' => body.size.to_s, 'Content-Type' => 'text/plain' }, + { Content_Length => body.size.to_s, Content_Type => Text_Plain }, [ body ] ] end def call(env) - if %r{\A/(.*)\z} =~ env["PATH_INFO"] + if %r{\A/(.*)\z} =~ env[PATH_INFO] key = unescape($1) - case env["REQUEST_METHOD"] + case env[REQUEST_METHOD] when "GET" get(key, env) when "HEAD" -- cgit v1.2.3-24-ge0c7